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