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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « net/http/http_util.h ('k') | net/server/http_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The rules for parsing content-types were borrowed from Firefox: 5 // The rules for parsing content-types were borrowed from Firefox:
6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
7 7
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // search_start now points to the first char after the end of the 70 // search_start now points to the first char after the end of the
71 // string, so just go back to the top of the loop and look for 71 // string, so just go back to the top of the loop and look for
72 // |delimiter| again. 72 // |delimiter| again.
73 } while (true); 73 } while (true);
74 74
75 NOTREACHED(); 75 NOTREACHED();
76 return line.length(); 76 return line.length();
77 } 77 }
78 78
79 // static 79 // static
80 bool HttpUtil::ParseVersion(const std::string& version_str,
81 HttpVersion* version) {
82 std::string::const_iterator p = version_str.begin();
83
84 // RFC2616 sec 3.1: HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
85 // TODO: (1*DIGIT apparently means one or more digits, but we only handle 1).
86 // TODO: handle leading zeros, which is allowed by the rfc1616 sec 3.1.
87
88 if (version_str.length() < 4 || !LowerCaseEqualsASCII(p, p + 4, "http")) {
89 DVLOG(1) << "missing status line";
90 return false;
91 }
92
93 p += 4;
94
95 if (p >= version_str.end() || *p != '/') {
96 DVLOG(1) << "missing version";
97 return false;
98 }
99
100 std::string::const_iterator dot = std::find(p, version_str.end(), '.');
101 if (dot == version_str.end()) {
102 DVLOG(1) << "malformed version";
103 return false;
104 }
105
106 ++p; // from / to first digit.
107 ++dot; // from . to second digit.
108
109 if (!(*p >= '0' && *p <= '9' && *dot >= '0' && *dot <= '9')) {
110 DVLOG(1) << "malformed version number";
111 return false;
112 }
113
114 uint16 major = *p - '0';
115 uint16 minor = *dot - '0';
116
117 *version = HttpVersion(major, minor);
118 return true;
119 }
120
121 // static
80 void HttpUtil::ParseContentType(const std::string& content_type_str, 122 void HttpUtil::ParseContentType(const std::string& content_type_str,
81 std::string* mime_type, 123 std::string* mime_type,
82 std::string* charset, 124 std::string* charset,
83 bool* had_charset, 125 bool* had_charset,
84 std::string* boundary) { 126 std::string* boundary) {
85 const std::string::const_iterator begin = content_type_str.begin(); 127 const std::string::const_iterator begin = content_type_str.begin();
86 128
87 // Trim leading and trailing whitespace from type. We include '(' in 129 // Trim leading and trailing whitespace from type. We include '(' in
88 // the trailing trim set to catch media-type comments, which are not at all 130 // the trailing trim set to catch media-type comments, which are not at all
89 // standard, but may occur in rare cases. 131 // standard, but may occur in rare cases.
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 value_is_quoted_ = true; 940 value_is_quoted_ = true;
899 // Do not store iterators into this. See declaration of unquoted_value_. 941 // Do not store iterators into this. See declaration of unquoted_value_.
900 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 942 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
901 } 943 }
902 } 944 }
903 945
904 return true; 946 return true;
905 } 947 }
906 948
907 } // namespace net 949 } // namespace net
OLDNEW
« 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