diff options
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_response_headers.cc | 18 | ||||
-rw-r--r-- | net/http/http_response_headers_unittest.cc | 30 |
2 files changed, 38 insertions, 10 deletions
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index ba96476..604a522 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -199,7 +199,7 @@ void HttpResponseHeaders::Parse(const string& raw_input) { // has_headers = true, if there is any data following the status line. // Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0. bool has_headers = line_end != raw_input.end() && - (line_end + 1) != raw_input.end() && *(line_end + 1) != '\0'; + (line_end + 1) != raw_input.end() && *(line_end + 1) != '\0'; ParseStatusLine(line_begin, line_end, has_headers); if (line_end == raw_input.end()) { @@ -316,8 +316,6 @@ string HttpResponseHeaders::GetStatusLine() const { } std::string HttpResponseHeaders::GetStatusText() const { - // TODO(eroman): this needs a unit test. - // GetStatusLine() is already normalized, so it has the format: // <http_version> SP <response_code> SP <status_text> std::string status_text = GetStatusLine(); @@ -480,14 +478,14 @@ void HttpResponseHeaders::ParseStatusLine(string::const_iterator line_begin, if (p == code) { DLOG(INFO) << "missing response status number; assuming 200"; - raw_headers_.append(" 200 "); + raw_headers_.append(" 200 OK"); response_code_ = 200; - } else { - raw_headers_.push_back(' '); - raw_headers_.append(code, p); - raw_headers_.push_back(' '); - response_code_ = static_cast<int>(StringToInt64(string(code, p))); - } + return; + } + raw_headers_.push_back(' '); + raw_headers_.append(code, p); + raw_headers_.push_back(' '); + response_code_ = static_cast<int>(StringToInt64(string(code, p))); // Skip whitespace. while (*p == ' ') diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index f02cd7f..6159e93 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -1041,3 +1041,33 @@ TEST(HttpResponseHeadersTest, IsKeepAlive) { } } +TEST(HttpResponseHeadersTest, GetStatusText) { + std::string headers("HTTP/1.1 404 Not Found"); + HeadersToRaw(&headers); + scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); + EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); +} + +TEST(HttpResponseHeadersTest, GetStatusTextMissing) { + std::string headers("HTTP/1.1 404"); + HeadersToRaw(&headers); + scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); + // Since the status line gets normalized, we have OK + EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); +} + +TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) { + std::string headers("HTTP/1.0 404 Not Found"); + HeadersToRaw(&headers); + scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); + EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); +} + +TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { + std::string headers("Foo bar."); + HeadersToRaw(&headers); + scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); + // The bad status line would have gotten rewritten as + // HTTP/1.0 200 OK. + EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); +} |