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

Side by Side Diff: services/http_server/http_request_parser.cc

Issue 2022983003: Roll base to 5e00da80f6adb7082d1c0e88d3274cf87cc43bc5 and tonic to f7acabb8fa6c91124486a41194eac3cd… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "services/http_server/http_request_parser.h" 5 #include "services/http_server/http_request_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() { 73 HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() {
74 // Check if the all request headers are available. 74 // Check if the all request headers are available.
75 if (buffer_.find("\r\n\r\n", buffer_position_) == std::string::npos) 75 if (buffer_.find("\r\n\r\n", buffer_position_) == std::string::npos)
76 return WAITING; 76 return WAITING;
77 77
78 // Parse request's the first header line. 78 // Parse request's the first header line.
79 // Request main main header, eg. GET /foobar.html HTTP/1.1 79 // Request main main header, eg. GET /foobar.html HTTP/1.1
80 { 80 {
81 const std::string header_line = ShiftLine(); 81 const std::string header_line = ShiftLine();
82 std::vector<std::string> header_line_tokens; 82 std::vector<std::string> header_line_tokens = base::SplitString(
83 base::SplitString(header_line, ' ', &header_line_tokens); 83 header_line, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
84 DCHECK_EQ(3u, header_line_tokens.size()); 84 DCHECK_EQ(3u, header_line_tokens.size());
85 // Method. 85 // Method.
86 http_request_->method = header_line_tokens[0]; 86 http_request_->method = header_line_tokens[0];
87 // Address. 87 // Address.
88 // Don't build an absolute URL as the parser does not know (should not 88 // Don't build an absolute URL as the parser does not know (should not
89 // know) anything about the server address. 89 // know) anything about the server address.
90 http_request_->relative_url = header_line_tokens[1]; 90 http_request_->relative_url = header_line_tokens[1];
91 // Protocol. 91 // Protocol.
92 const std::string protocol = 92 const std::string protocol = base::ToLowerASCII(header_line_tokens[2]);
93 base::StringToLowerASCII(header_line_tokens[2]);
94 CHECK(protocol == "http/1.0" || protocol == "http/1.1") << 93 CHECK(protocol == "http/1.0" || protocol == "http/1.1") <<
95 "Protocol not supported: " << protocol; 94 "Protocol not supported: " << protocol;
96 } 95 }
97 96
98 // Parse further headers. 97 // Parse further headers.
99 { 98 {
100 std::string header_name; 99 std::string header_name;
101 while (true) { 100 while (true) {
102 std::string header_line = ShiftLine(); 101 std::string header_line = ShiftLine();
103 if (header_line.empty()) 102 if (header_line.empty())
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 state_ = STATE_CONTENT; 180 state_ = STATE_CONTENT;
182 return WAITING; 181 return WAITING;
183 } 182 }
184 183
185 HttpRequestPtr HttpRequestParser::GetRequest() { 184 HttpRequestPtr HttpRequestParser::GetRequest() {
186 DCHECK_EQ(STATE_ACCEPTED, state_); 185 DCHECK_EQ(STATE_ACCEPTED, state_);
187 return http_request_.Pass(); 186 return http_request_.Pass();
188 } 187 }
189 188
190 } // namespace http_server 189 } // namespace http_server
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698