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

Unified Diff: net/http/http_util.cc

Issue 251213004: HttpServer: avoid DCHECK'ing on non-HTTP/1.1 requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rm spurious nl 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_util.h ('k') | net/server/http_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_util.cc
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index f4f994af6052f294bb52e1714cf1ca625af1cadc..481b1047d2122c58c9328ac61b3508c7fd2008d4 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -77,6 +77,48 @@ size_t HttpUtil::FindDelimiter(const std::string& line,
}
// static
+bool HttpUtil::ParseVersion(const std::string& version_str,
+ HttpVersion* version) {
+ std::string::const_iterator p = version_str.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 (version_str.length() < 4 || !LowerCaseEqualsASCII(p, p + 4, "http")) {
+ DVLOG(1) << "missing status line";
+ return false;
+ }
+
+ p += 4;
+
+ if (p >= version_str.end() || *p != '/') {
+ DVLOG(1) << "missing version";
+ return false;
+ }
+
+ std::string::const_iterator dot = std::find(p, version_str.end(), '.');
+ if (dot == version_str.end()) {
+ DVLOG(1) << "malformed version";
+ return false;
+ }
+
+ ++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 false;
+ }
+
+ uint16 major = *p - '0';
+ uint16 minor = *dot - '0';
+
+ *version = HttpVersion(major, minor);
+ return true;
+}
+
+// static
void HttpUtil::ParseContentType(const std::string& content_type_str,
std::string* mime_type,
std::string* charset,
« no previous file with comments | « net/http/http_util.h ('k') | net/server/http_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698