aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2007-04-02 18:24:16 +0000
committermmentovai <mmentovai@4c0a9323-5329-0410-9bdc-e9ce6186880e>2007-04-02 18:24:16 +0000
commit1de8bed899cc08b3453753132d137b8a953a4e8d (patch)
tree08f8feaddbdc3d0c7f7be72cad50f8465786fa08 /src
parentvswprintf causes Purify to fail (#145). r=darin (diff)
downloadbreakpad-1de8bed899cc08b3453753132d137b8a953a4e8d.tar.xz
Windows http_upload should allow response without Content-Length header (#144).
Patch by Ted Mielczarek. r=me http://groups.google.com/group/google-breakpad-dev/browse_thread/thread/a401434f639e5b2f git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@136 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src')
-rw-r--r--src/common/windows/http_upload.cc50
1 files changed, 33 insertions, 17 deletions
diff --git a/src/common/windows/http_upload.cc b/src/common/windows/http_upload.cc
index 86ecf37a..aef046ad 100644
--- a/src/common/windows/http_upload.cc
+++ b/src/common/windows/http_upload.cc
@@ -174,31 +174,47 @@ bool HTTPUpload::SendRequest(const wstring &url,
// static
bool HTTPUpload::ReadResponse(HINTERNET request, wstring *response) {
+ bool has_content_length_header = false;
wchar_t content_length[32];
DWORD content_length_size = sizeof(content_length);
- if (!HttpQueryInfo(request, HTTP_QUERY_CONTENT_LENGTH,
- static_cast<LPVOID>(&content_length), &content_length_size,
- 0)) {
- return false;
+ DWORD claimed_size;
+ string response_body;
+
+ if (HttpQueryInfo(request, HTTP_QUERY_CONTENT_LENGTH,
+ static_cast<LPVOID>(&content_length),
+ &content_length_size, 0)) {
+ has_content_length_header = true;
+ claimed_size = wcstol(content_length, NULL, 10);
+ response_body.reserve(claimed_size);
}
- DWORD claimed_size = wcstol(content_length, NULL, 10);
- char *response_buffer = new char[claimed_size];
- DWORD size_read;
+
+ DWORD bytes_available;
DWORD total_read = 0;
- BOOL read_result;
- do {
- read_result = InternetReadFile(request, response_buffer + total_read,
- claimed_size - total_read, &size_read);
- total_read += size_read;
- } while (read_result && (size_read != 0) && (total_read < claimed_size));
-
- bool succeeded = (total_read == claimed_size);
+ bool return_code;
+
+ while ((return_code = InternetQueryDataAvailable(request, &bytes_available,
+ 0, 0) != 0) &&
+ bytes_available > 0) {
+ vector<char> response_buffer(bytes_available);
+ DWORD size_read;
+
+ if ((return_code = InternetReadFile(request, &response_buffer[0],
+ bytes_available, &size_read) != 0) &&
+ size_read > 0) {
+ total_read += size_read;
+ response_body.append(&response_buffer[0], size_read);
+ } else {
+ break;
+ }
+ }
+
+ bool succeeded = return_code && (!has_content_length_header ||
+ (total_read == claimed_size));
if (succeeded && response) {
- *response = UTF8ToWide(string(response_buffer, total_read));
+ *response = UTF8ToWide(response_body);
}
- delete[] response_buffer;
return succeeded;
}