| 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 // 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 339 } |
| 340 | 340 |
| 341 // static | 341 // static |
| 342 bool HttpUtil::IsValidHeaderValue(const std::string& value) { | 342 bool HttpUtil::IsValidHeaderValue(const std::string& value) { |
| 343 // Just a sanity check: disallow NUL and CRLF. | 343 // Just a sanity check: disallow NUL and CRLF. |
| 344 return value.find('\0') == std::string::npos && | 344 return value.find('\0') == std::string::npos && |
| 345 value.find("\r\n") == std::string::npos; | 345 value.find("\r\n") == std::string::npos; |
| 346 } | 346 } |
| 347 | 347 |
| 348 // static | 348 // static |
| 349 bool HttpUtil::IsValidHeaderValueRFC7230(const base::StringPiece& value) { |
| 350 // This empty string is a valid header-value. |
| 351 if (value.empty()) |
| 352 return true; |
| 353 |
| 354 // Check leading/trailing whitespaces. |
| 355 if (IsLWS(value[0]) || IsLWS(value[value.size() - 1])) |
| 356 return false; |
| 357 |
| 358 // Check each octet is |field-vchar|, |SP| or |HTAB|. |
| 359 for (unsigned char c : value) { |
| 360 if (c == 0x7F || (c < 0x20 && c != '\t')) |
| 361 return false; |
| 362 } |
| 363 return true; |
| 364 } |
| 365 |
| 366 // static |
| 349 std::string HttpUtil::StripHeaders(const std::string& headers, | 367 std::string HttpUtil::StripHeaders(const std::string& headers, |
| 350 const char* const headers_to_remove[], | 368 const char* const headers_to_remove[], |
| 351 size_t headers_to_remove_len) { | 369 size_t headers_to_remove_len) { |
| 352 std::string stripped_headers; | 370 std::string stripped_headers; |
| 353 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 371 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| 354 | 372 |
| 355 while (it.GetNext()) { | 373 while (it.GetNext()) { |
| 356 bool should_remove = false; | 374 bool should_remove = false; |
| 357 for (size_t i = 0; i < headers_to_remove_len; ++i) { | 375 for (size_t i = 0; i < headers_to_remove_len; ++i) { |
| 358 if (base::LowerCaseEqualsASCII( | 376 if (base::LowerCaseEqualsASCII( |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 value_is_quoted_ = true; | 959 value_is_quoted_ = true; |
| 942 // Do not store iterators into this. See declaration of unquoted_value_. | 960 // Do not store iterators into this. See declaration of unquoted_value_. |
| 943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 961 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
| 944 } | 962 } |
| 945 } | 963 } |
| 946 | 964 |
| 947 return true; | 965 return true; |
| 948 } | 966 } |
| 949 | 967 |
| 950 } // namespace net | 968 } // namespace net |
| OLD | NEW |