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

Side by Side Diff: net/test/embedded_test_server/http_request.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 (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 #include "net/test/embedded_test_server/http_request.h" 5 #include "net/test/embedded_test_server/http_request.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_util.h" 10 #include "base/strings/string_util.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return WAITING; 76 return WAITING;
77 } 77 }
78 78
79 HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() { 79 HttpRequestParser::ParseResult HttpRequestParser::ParseHeaders() {
80 // Check if the all request headers are available. 80 // Check if the all request headers are available.
81 if (buffer_.find("\r\n\r\n", buffer_position_) == std::string::npos) 81 if (buffer_.find("\r\n\r\n", buffer_position_) == std::string::npos)
82 return WAITING; 82 return WAITING;
83 83
84 // Parse request's the first header line. 84 // Parse request's the first header line.
85 // Request main main header, eg. GET /foobar.html HTTP/1.1 85 // Request main main header, eg. GET /foobar.html HTTP/1.1
86 std::string request_headers;
86 { 87 {
87 const std::string header_line = ShiftLine(); 88 const std::string header_line = ShiftLine();
89 http_request_->all_headers += header_line + "\r\n";
88 std::vector<std::string> header_line_tokens; 90 std::vector<std::string> header_line_tokens;
89 base::SplitString(header_line, ' ', &header_line_tokens); 91 base::SplitString(header_line, ' ', &header_line_tokens);
90 DCHECK_EQ(3u, header_line_tokens.size()); 92 DCHECK_EQ(3u, header_line_tokens.size());
91 // Method. 93 // Method.
92 http_request_->method_string = header_line_tokens[0]; 94 http_request_->method_string = header_line_tokens[0];
93 http_request_->method = GetMethodType(base::StringToLowerASCII( 95 http_request_->method = GetMethodType(base::StringToLowerASCII(
94 header_line_tokens[0])); 96 header_line_tokens[0]));
95 // Address. 97 // Address.
96 // Don't build an absolute URL as the parser does not know (should not 98 // Don't build an absolute URL as the parser does not know (should not
97 // know) anything about the server address. 99 // know) anything about the server address.
98 http_request_->relative_url = header_line_tokens[1]; 100 http_request_->relative_url = header_line_tokens[1];
99 // Protocol. 101 // Protocol.
100 const std::string protocol = 102 const std::string protocol =
101 base::StringToLowerASCII(header_line_tokens[2]); 103 base::StringToLowerASCII(header_line_tokens[2]);
102 CHECK(protocol == "http/1.0" || protocol == "http/1.1") << 104 CHECK(protocol == "http/1.0" || protocol == "http/1.1") <<
103 "Protocol not supported: " << protocol; 105 "Protocol not supported: " << protocol;
104 } 106 }
105 107
106 // Parse further headers. 108 // Parse further headers.
107 { 109 {
108 std::string header_name; 110 std::string header_name;
109 while (true) { 111 while (true) {
110 std::string header_line = ShiftLine(); 112 std::string header_line = ShiftLine();
111 if (header_line.empty()) 113 if (header_line.empty())
112 break; 114 break;
113 115
116 http_request_->all_headers += header_line + "\r\n";
114 if (header_line[0] == ' ' || header_line[0] == '\t') { 117 if (header_line[0] == ' ' || header_line[0] == '\t') {
115 // Continuation of the previous multi-line header. 118 // Continuation of the previous multi-line header.
116 std::string header_value = 119 std::string header_value =
117 Trim(header_line.substr(1, header_line.size() - 1)); 120 Trim(header_line.substr(1, header_line.size() - 1));
118 http_request_->headers[header_name] += " " + header_value; 121 http_request_->headers[header_name] += " " + header_value;
119 } else { 122 } else {
120 // New header. 123 // New header.
121 size_t delimiter_pos = header_line.find(":"); 124 size_t delimiter_pos = header_line.find(":");
122 DCHECK_NE(std::string::npos, delimiter_pos) << "Syntax error."; 125 DCHECK_NE(std::string::npos, delimiter_pos) << "Syntax error.";
123 header_name = Trim(header_line.substr(0, delimiter_pos)); 126 header_name = Trim(header_line.substr(0, delimiter_pos));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return METHOD_DELETE; 198 return METHOD_DELETE;
196 } else if (token == "patch") { 199 } else if (token == "patch") {
197 return METHOD_PATCH; 200 return METHOD_PATCH;
198 } 201 }
199 NOTREACHED() << "Method not implemented: " << token; 202 NOTREACHED() << "Method not implemented: " << token;
200 return METHOD_UNKNOWN; 203 return METHOD_UNKNOWN;
201 } 204 }
202 205
203 } // namespace test_server 206 } // namespace test_server
204 } // namespace net 207 } // namespace net
OLDNEW
« no previous file with comments | « net/test/embedded_test_server/http_request.h ('k') | net/test/embedded_test_server/http_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698