Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: util/net/http_transport_win.cc

Issue 885183004: HTTPTransport: callers should be able to obtain the HTTP response body (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Update other comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/net/http_transport_test_server.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/net/http_transport_win.cc
diff --git a/util/net/http_transport_win.cc b/util/net/http_transport_win.cc
index 8e1cef31ca401db45f1bbb149ee20e0fa65a3f4e..99f87ba26cc63d0c95ce4c3f66097c6f6d2a4cb4 100644
--- a/util/net/http_transport_win.cc
+++ b/util/net/http_transport_win.cc
@@ -73,7 +73,7 @@ class HTTPTransportWin final : public HTTPTransport {
HTTPTransportWin();
~HTTPTransportWin() override;
- bool ExecuteSynchronously() override;
+ bool ExecuteSynchronously(std::string* response_body) override;
private:
DISALLOW_COPY_AND_ASSIGN(HTTPTransportWin);
@@ -85,7 +85,7 @@ HTTPTransportWin::HTTPTransportWin() : HTTPTransport() {
HTTPTransportWin::~HTTPTransportWin() {
}
-bool HTTPTransportWin::ExecuteSynchronously() {
+bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
ScopedHINTERNET session(
WinHttpOpen(base::UTF8ToUTF16(PACKAGE_NAME "/" PACKAGE_VERSION).c_str(),
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
@@ -154,8 +154,9 @@ bool HTTPTransportWin::ExecuteSynchronously() {
std::vector<uint8_t> post_data;
// Write the body of a POST if any.
+ const size_t kBufferSize = 4096;
for (;;) {
- uint8_t buffer[4096];
+ uint8_t buffer[kBufferSize];
ssize_t bytes_to_write =
body_stream()->GetBytesBuffer(buffer, sizeof(buffer));
if (bytes_to_write == 0)
@@ -198,8 +199,25 @@ bool HTTPTransportWin::ExecuteSynchronously() {
return false;
}
- // TODO(scottmg): Retrieve body of response if necessary with
- // WinHttpQueryDataAvailable and WinHttpReadData.
+ if (response_body) {
+ response_body->clear();
+
+ // There isn’t any reason to call WinHttpQueryDataAvailable(), because it
+ // returns the number of bytes available to be read without blocking at the
+ // time of the call, not the number of bytes until end-of-file. This method,
+ // which executes synchronously, is only concerned with reading until EOF.
+ DWORD bytes_read = 0;
+ do {
+ char read_buffer[kBufferSize];
+ if (!WinHttpReadData(
+ request.get(), read_buffer, sizeof(read_buffer), &bytes_read)) {
+ LogErrorWinHttpMessage("WinHttpReadData");
+ return false;
+ }
+
+ response_body->append(read_buffer, bytes_read);
+ } while (bytes_read > 0);
+ }
return true;
}
« no previous file with comments | « util/net/http_transport_test_server.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698