Treat response codes in [200..203] as successful

Some crash recorders respond with non-200 2xx responses on success, e.g.
HockeyApp which responds with 202 Accepted.

Change-Id: I40de12155b44f7638a1c726090657938e3b1b557
Reviewed-on: https://chromium-review.googlesource.com/1167793
Commit-Queue: Jeremy Apthorp <jeremya@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Jeremy Apthorp 2018-08-09 16:41:44 -07:00 committed by Commit Bot
parent 2906581f10
commit f540abb506
5 changed files with 16 additions and 8 deletions

View File

@ -90,7 +90,7 @@ class HTTPTransport {
//! if the response body is not required.
//!
//! \return Whether or not the request was successful, defined as returning
//! a HTTP status 200 (OK) code.
//! a HTTP status code in the range 200-203 (inclusive).
virtual bool ExecuteSynchronously(std::string* response_body) = 0;
protected:

View File

@ -293,7 +293,7 @@ bool HTTPTransportMac::ExecuteSynchronously(std::string* response_body) {
return false;
}
NSInteger http_status = [http_response statusCode];
if (http_status != 200) {
if (http_status < 200 || http_status > 203) {
LOG(ERROR) << base::StringPrintf("HTTP status %ld",
implicit_cast<long>(http_status));
return false;

View File

@ -457,10 +457,18 @@ bool ReadResponseLine(Stream* stream) {
LOG(ERROR) << "ReadLine";
return false;
}
static constexpr const char kHttp10[] = "HTTP/1.0 200 ";
static constexpr const char kHttp11[] = "HTTP/1.1 200 ";
return StartsWith(response_line, kHttp10, strlen(kHttp10)) ||
StartsWith(response_line, kHttp11, strlen(kHttp11));
static constexpr const char kHttp10[] = "HTTP/1.0 ";
static constexpr const char kHttp11[] = "HTTP/1.1 ";
if (!(StartsWith(response_line, kHttp10, strlen(kHttp10)) ||
StartsWith(response_line, kHttp11, strlen(kHttp11))) ||
response_line.size() < strlen(kHttp10) + 3 ||
response_line.at(strlen(kHttp10) + 3) != ' ') {
return false;
}
unsigned int http_status = 0;
return base::StringToUint(response_line.substr(strlen(kHttp10), 3),
&http_status) &&
http_status >= 200 && http_status <= 203;
}
bool ReadResponseHeaders(Stream* stream, HTTPHeaders* headers) {

View File

@ -137,7 +137,7 @@ class HTTPTransportTestFixture : public MultiprocessExec {
std::string response_body;
bool success = transport->ExecuteSynchronously(&response_body);
if (response_code_ == 200) {
if (response_code_ >= 200 && response_code_ <= 203) {
EXPECT_TRUE(success);
std::string expect_response_body = random_string + "\r\n";
EXPECT_EQ(response_body, expect_response_body);

View File

@ -375,7 +375,7 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
return false;
}
if (status_code != 200) {
if (status_code < 200 || status_code > 203) {
LOG(ERROR) << base::StringPrintf("HTTP status %lu", status_code);
return false;
}