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

Unified Diff: net/http/http_response_headers.cc

Issue 265603002: Revert of HttpServer: avoid DCHECK'ing on non-HTTP/1.1 requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 | « net/http/http_response_headers.h ('k') | net/http/http_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 408739b3876d3b838adab677f87272bd395b05a3..cc4cec4d8878678a9760449a669cbd5599c44176 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -627,21 +627,62 @@
// Note: this implementation implicitly assumes that line_end points at a valid
// sentinel character (such as '\0').
+// static
+HttpVersion HttpResponseHeaders::ParseVersion(
+ std::string::const_iterator line_begin,
+ std::string::const_iterator line_end) {
+ std::string::const_iterator p = line_begin;
+
+ // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
+ // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1).
+ // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
+
+ if ((line_end - p < 4) || !LowerCaseEqualsASCII(p, p + 4, "http")) {
+ DVLOG(1) << "missing status line";
+ return HttpVersion();
+ }
+
+ p += 4;
+
+ if (p >= line_end || *p != '/') {
+ DVLOG(1) << "missing version";
+ return HttpVersion();
+ }
+
+ std::string::const_iterator dot = std::find(p, line_end, '.');
+ if (dot == line_end) {
+ DVLOG(1) << "malformed version";
+ return HttpVersion();
+ }
+
+ ++p; // from / to first digit.
+ ++dot; // from . to second digit.
+
+ if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) {
+ DVLOG(1) << "malformed version number";
+ return HttpVersion();
+ }
+
+ uint16 major = *p - '0';
+ uint16 minor = *dot - '0';
+
+ return HttpVersion(major, minor);
+}
+
+// Note: this implementation implicitly assumes that line_end points at a valid
+// sentinel character (such as '\0').
void HttpResponseHeaders::ParseStatusLine(
std::string::const_iterator line_begin,
std::string::const_iterator line_end,
bool has_headers) {
// Extract the version number
- std::string::const_iterator first_space =
- std::find(line_begin, line_end, ' ');
- std::string version(line_begin, first_space);
- bool success = HttpUtil::ParseVersion(version, &parsed_http_version_);
+ parsed_http_version_ = ParseVersion(line_begin, line_end);
// Clamp the version number to one of: {0.9, 1.0, 1.1}
- if (success && parsed_http_version_ == HttpVersion(0, 9) && !has_headers) {
+ if (parsed_http_version_ == HttpVersion(0, 9) && !has_headers) {
http_version_ = HttpVersion(0, 9);
raw_headers_ = "HTTP/0.9";
- } else if (success && parsed_http_version_ >= HttpVersion(1, 1)) {
+ } else if (parsed_http_version_ >= HttpVersion(1, 1)) {
http_version_ = HttpVersion(1, 1);
raw_headers_ = "HTTP/1.1";
} else {
@@ -655,7 +696,7 @@
}
// TODO(eroman): this doesn't make sense if ParseVersion failed.
- std::string::const_iterator p = first_space;
+ std::string::const_iterator p = std::find(line_begin, line_end, ' ');
if (p == line_end) {
DVLOG(1) << "missing response status; assuming 200 OK";
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698