OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/net/http_transport.h" | 15 #include "util/net/http_transport.h" |
16 | 16 |
17 #include <windows.h> | 17 #include <windows.h> |
18 #include <winhttp.h> | 18 #include <winhttp.h> |
19 | 19 |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/numerics/safe_conversions.h" |
21 #include "base/scoped_generic.h" | 22 #include "base/scoped_generic.h" |
22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
24 #include "util/net/http_body.h" | 25 #include "util/net/http_body.h" |
25 #include "package.h" | 26 #include "package.h" |
26 | 27 |
27 namespace crashpad { | 28 namespace crashpad { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 0)); | 143 0)); |
143 if (!request.get()) { | 144 if (!request.get()) { |
144 LogErrorWinHttpMessage("WinHttpOpenRequest"); | 145 LogErrorWinHttpMessage("WinHttpOpenRequest"); |
145 return false; | 146 return false; |
146 } | 147 } |
147 | 148 |
148 // Add headers to the request. | 149 // Add headers to the request. |
149 for (const auto& pair : headers()) { | 150 for (const auto& pair : headers()) { |
150 std::wstring header_string = | 151 std::wstring header_string = |
151 base::UTF8ToUTF16(pair.first) + L": " + base::UTF8ToUTF16(pair.second); | 152 base::UTF8ToUTF16(pair.first) + L": " + base::UTF8ToUTF16(pair.second); |
152 if (!WinHttpAddRequestHeaders(request.get(), | 153 if (!WinHttpAddRequestHeaders( |
153 header_string.c_str(), | 154 request.get(), |
154 header_string.size(), | 155 header_string.c_str(), |
155 WINHTTP_ADDREQ_FLAG_ADD)) { | 156 base::checked_cast<DWORD>(header_string.size()), |
| 157 WINHTTP_ADDREQ_FLAG_ADD)) { |
156 LogErrorWinHttpMessage("WinHttpAddRequestHeaders"); | 158 LogErrorWinHttpMessage("WinHttpAddRequestHeaders"); |
157 return false; | 159 return false; |
158 } | 160 } |
159 } | 161 } |
160 | 162 |
161 // We need the Content-Length up front, so buffer in memory. We should modify | 163 // We need the Content-Length up front, so buffer in memory. We should modify |
162 // the interface to not require this, and then use WinHttpWriteData after | 164 // the interface to not require this, and then use WinHttpWriteData after |
163 // WinHttpSendRequest. | 165 // WinHttpSendRequest. |
164 std::vector<uint8_t> post_data; | 166 std::vector<uint8_t> post_data; |
165 | 167 |
166 // Write the body of a POST if any. | 168 // Write the body of a POST if any. |
167 const size_t kBufferSize = 4096; | 169 const size_t kBufferSize = 4096; |
168 for (;;) { | 170 for (;;) { |
169 uint8_t buffer[kBufferSize]; | 171 uint8_t buffer[kBufferSize]; |
170 ssize_t bytes_to_write = | 172 ssize_t bytes_to_write = |
171 body_stream()->GetBytesBuffer(buffer, sizeof(buffer)); | 173 body_stream()->GetBytesBuffer(buffer, sizeof(buffer)); |
172 if (bytes_to_write == 0) | 174 if (bytes_to_write == 0) |
173 break; | 175 break; |
174 post_data.insert(post_data.end(), buffer, buffer + bytes_to_write); | 176 post_data.insert(post_data.end(), buffer, buffer + bytes_to_write); |
175 } | 177 } |
176 | 178 |
177 if (!WinHttpSendRequest(request.get(), | 179 if (!WinHttpSendRequest(request.get(), |
178 WINHTTP_NO_ADDITIONAL_HEADERS, | 180 WINHTTP_NO_ADDITIONAL_HEADERS, |
179 0, | 181 0, |
180 &post_data[0], | 182 &post_data[0], |
181 post_data.size(), | 183 base::checked_cast<DWORD>(post_data.size()), |
182 post_data.size(), | 184 base::checked_cast<DWORD>(post_data.size()), |
183 0)) { | 185 0)) { |
184 LogErrorWinHttpMessage("WinHttpSendRequest"); | 186 LogErrorWinHttpMessage("WinHttpSendRequest"); |
185 return false; | 187 return false; |
186 } | 188 } |
187 | 189 |
188 if (!WinHttpReceiveResponse(request.get(), nullptr)) { | 190 if (!WinHttpReceiveResponse(request.get(), nullptr)) { |
189 LogErrorWinHttpMessage("WinHttpReceiveResponse"); | 191 LogErrorWinHttpMessage("WinHttpReceiveResponse"); |
190 return false; | 192 return false; |
191 } | 193 } |
192 | 194 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 235 } |
234 | 236 |
235 } // namespace | 237 } // namespace |
236 | 238 |
237 // static | 239 // static |
238 scoped_ptr<HTTPTransport> HTTPTransport::Create() { | 240 scoped_ptr<HTTPTransport> HTTPTransport::Create() { |
239 return scoped_ptr<HTTPTransportWin>(new HTTPTransportWin); | 241 return scoped_ptr<HTTPTransportWin>(new HTTPTransportWin); |
240 } | 242 } |
241 | 243 |
242 } // namespace crashpad | 244 } // namespace crashpad |
OLD | NEW |