| 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/numerics/safe_conversions.h" |
| 22 #include "base/scoped_generic.h" | 22 #include "base/scoped_generic.h" |
| 23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "package.h" |
| 26 #include "util/file/file_io.h" |
| 25 #include "util/net/http_body.h" | 27 #include "util/net/http_body.h" |
| 26 #include "package.h" | |
| 27 | 28 |
| 28 namespace crashpad { | 29 namespace crashpad { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // PLOG doesn't work for messages from WinHTTP, so we need to use | 33 // PLOG doesn't work for messages from WinHTTP, so we need to use |
| 33 // FORMAT_MESSAGE_FROM_HMODULE + the dll name manually here. | 34 // FORMAT_MESSAGE_FROM_HMODULE + the dll name manually here. |
| 34 void LogErrorWinHttpMessage(const char* extra) { | 35 void LogErrorWinHttpMessage(const char* extra) { |
| 35 DWORD error_code = GetLastError(); | 36 DWORD error_code = GetLastError(); |
| 36 char msgbuf[256]; | 37 char msgbuf[256]; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 168 |
| 168 // We need the Content-Length up front, so buffer in memory. We should modify | 169 // We need the Content-Length up front, so buffer in memory. We should modify |
| 169 // the interface to not require this, and then use WinHttpWriteData after | 170 // the interface to not require this, and then use WinHttpWriteData after |
| 170 // WinHttpSendRequest. | 171 // WinHttpSendRequest. |
| 171 std::vector<uint8_t> post_data; | 172 std::vector<uint8_t> post_data; |
| 172 | 173 |
| 173 // Write the body of a POST if any. | 174 // Write the body of a POST if any. |
| 174 const size_t kBufferSize = 4096; | 175 const size_t kBufferSize = 4096; |
| 175 for (;;) { | 176 for (;;) { |
| 176 uint8_t buffer[kBufferSize]; | 177 uint8_t buffer[kBufferSize]; |
| 177 ssize_t bytes_to_write = | 178 FileOperationResult bytes_to_write = |
| 178 body_stream()->GetBytesBuffer(buffer, sizeof(buffer)); | 179 body_stream()->GetBytesBuffer(buffer, sizeof(buffer)); |
| 179 if (bytes_to_write == 0) | 180 if (bytes_to_write == 0) |
| 180 break; | 181 break; |
| 181 post_data.insert(post_data.end(), buffer, buffer + bytes_to_write); | 182 post_data.insert(post_data.end(), buffer, buffer + bytes_to_write); |
| 182 } | 183 } |
| 183 | 184 |
| 184 if (!WinHttpSendRequest(request.get(), | 185 if (!WinHttpSendRequest(request.get(), |
| 185 WINHTTP_NO_ADDITIONAL_HEADERS, | 186 WINHTTP_NO_ADDITIONAL_HEADERS, |
| 186 0, | 187 0, |
| 187 &post_data[0], | 188 &post_data[0], |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace | 243 } // namespace |
| 243 | 244 |
| 244 // static | 245 // static |
| 245 scoped_ptr<HTTPTransport> HTTPTransport::Create() { | 246 scoped_ptr<HTTPTransport> HTTPTransport::Create() { |
| 246 return scoped_ptr<HTTPTransportWin>(new HTTPTransportWin); | 247 return scoped_ptr<HTTPTransportWin>(new HTTPTransportWin); |
| 247 } | 248 } |
| 248 | 249 |
| 249 } // namespace crashpad | 250 } // namespace crashpad |
| OLD | NEW |