| OLD | NEW | 
|---|
| 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" | 
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" | 
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" | 
| 13 #include "net/http/http_chunked_decoder.h" | 13 #include "net/http/http_chunked_decoder.h" | 
|  | 14 #include "url/gurl.h" | 
| 14 | 15 | 
| 15 namespace net { | 16 namespace net { | 
| 16 namespace test_server { | 17 namespace test_server { | 
| 17 | 18 | 
| 18 namespace { | 19 namespace { | 
| 19 | 20 | 
| 20 size_t kRequestSizeLimit = 64 * 1024 * 1024;  // 64 mb. | 21 size_t kRequestSizeLimit = 64 * 1024 * 1024;  // 64 mb. | 
| 21 | 22 | 
| 22 // Helper function used to trim tokens in http request headers. | 23 // Helper function used to trim tokens in http request headers. | 
| 23 std::string Trim(const std::string& value) { | 24 std::string Trim(const std::string& value) { | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 91     std::vector<std::string> header_line_tokens = base::SplitString( | 92     std::vector<std::string> header_line_tokens = base::SplitString( | 
| 92         header_line, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 93         header_line, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 
| 93     DCHECK_EQ(3u, header_line_tokens.size()); | 94     DCHECK_EQ(3u, header_line_tokens.size()); | 
| 94     // Method. | 95     // Method. | 
| 95     http_request_->method_string = header_line_tokens[0]; | 96     http_request_->method_string = header_line_tokens[0]; | 
| 96     http_request_->method = | 97     http_request_->method = | 
| 97         GetMethodType(base::ToLowerASCII(header_line_tokens[0])); | 98         GetMethodType(base::ToLowerASCII(header_line_tokens[0])); | 
| 98     // Address. | 99     // Address. | 
| 99     // Don't build an absolute URL as the parser does not know (should not | 100     // Don't build an absolute URL as the parser does not know (should not | 
| 100     // know) anything about the server address. | 101     // know) anything about the server address. | 
| 101     http_request_->relative_url = header_line_tokens[1]; | 102     GURL url(header_line_tokens[1]); | 
|  | 103     if (url.is_valid()) { | 
|  | 104       http_request_->relative_url = url.path(); | 
|  | 105     } else { | 
|  | 106       if (header_line_tokens[1][0] == '/') | 
|  | 107         http_request_->relative_url = header_line_tokens[1]; | 
|  | 108       else | 
|  | 109         http_request_->relative_url = "/" + header_line_tokens[1]; | 
|  | 110     } | 
|  | 111 | 
| 102     // Protocol. | 112     // Protocol. | 
| 103     const std::string protocol = base::ToLowerASCII(header_line_tokens[2]); | 113     const std::string protocol = base::ToLowerASCII(header_line_tokens[2]); | 
| 104     CHECK(protocol == "http/1.0" || protocol == "http/1.1") << | 114     CHECK(protocol == "http/1.0" || protocol == "http/1.1") << | 
| 105         "Protocol not supported: " << protocol; | 115         "Protocol not supported: " << protocol; | 
| 106   } | 116   } | 
| 107 | 117 | 
| 108   // Parse further headers. | 118   // Parse further headers. | 
| 109   { | 119   { | 
| 110     std::string header_name; | 120     std::string header_name; | 
| 111     while (true) { | 121     while (true) { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 132     } | 142     } | 
| 133   } | 143   } | 
| 134 | 144 | 
| 135   // Headers done. Is any content data attached to the request? | 145   // Headers done. Is any content data attached to the request? | 
| 136   declared_content_length_ = 0; | 146   declared_content_length_ = 0; | 
| 137   if (http_request_->headers.count("Content-Length") > 0) { | 147   if (http_request_->headers.count("Content-Length") > 0) { | 
| 138     http_request_->has_content = true; | 148     http_request_->has_content = true; | 
| 139     const bool success = base::StringToSizeT( | 149     const bool success = base::StringToSizeT( | 
| 140         http_request_->headers["Content-Length"], | 150         http_request_->headers["Content-Length"], | 
| 141         &declared_content_length_); | 151         &declared_content_length_); | 
| 142     DCHECK(success) << "Malformed Content-Length header's value."; | 152     if (!success) { | 
|  | 153       declared_content_length_ = 0; | 
|  | 154       LOG(WARNING) << "Malformed Content-Length header's value."; | 
|  | 155     } | 
| 143   } else if (http_request_->headers.count("Transfer-Encoding") > 0) { | 156   } else if (http_request_->headers.count("Transfer-Encoding") > 0) { | 
| 144     if (http_request_->headers["Transfer-Encoding"] == "chunked") { | 157     if (http_request_->headers["Transfer-Encoding"] == "chunked") { | 
| 145       http_request_->has_content = true; | 158       http_request_->has_content = true; | 
| 146       chunked_decoder_.reset(new HttpChunkedDecoder()); | 159       chunked_decoder_.reset(new HttpChunkedDecoder()); | 
| 147       state_ = STATE_CONTENT; | 160       state_ = STATE_CONTENT; | 
| 148       return WAITING; | 161       return WAITING; | 
| 149     } | 162     } | 
| 150   } | 163   } | 
| 151   if (declared_content_length_ == 0) { | 164   if (declared_content_length_ == 0) { | 
| 152     // No content data, so parsing is finished. | 165     // No content data, so parsing is finished. | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 217   } else if (token == "head") { | 230   } else if (token == "head") { | 
| 218     return METHOD_HEAD; | 231     return METHOD_HEAD; | 
| 219   } else if (token == "post") { | 232   } else if (token == "post") { | 
| 220     return METHOD_POST; | 233     return METHOD_POST; | 
| 221   } else if (token == "put") { | 234   } else if (token == "put") { | 
| 222     return METHOD_PUT; | 235     return METHOD_PUT; | 
| 223   } else if (token == "delete") { | 236   } else if (token == "delete") { | 
| 224     return METHOD_DELETE; | 237     return METHOD_DELETE; | 
| 225   } else if (token == "patch") { | 238   } else if (token == "patch") { | 
| 226     return METHOD_PATCH; | 239     return METHOD_PATCH; | 
|  | 240   } else if (token == "connect") { | 
|  | 241     return METHOD_CONNECT; | 
| 227   } | 242   } | 
| 228   NOTREACHED() << "Method not implemented: " << token; | 243   LOG(WARNING) << "Method not implemented: " << token; | 
| 229   return METHOD_UNKNOWN; | 244   return METHOD_GET; | 
| 230 } | 245 } | 
| 231 | 246 | 
| 232 }  // namespace test_server | 247 }  // namespace test_server | 
| 233 }  // namespace net | 248 }  // namespace net | 
| OLD | NEW | 
|---|