| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // include a comma, so this check makes us a bit more tolerant. | 126 // include a comma, so this check makes us a bit more tolerant. |
| 127 if (content_type_str.length() != 0 && | 127 if (content_type_str.length() != 0 && |
| 128 content_type_str != "*/*" && | 128 content_type_str != "*/*" && |
| 129 content_type_str.find_first_of('/') != std::string::npos) { | 129 content_type_str.find_first_of('/') != std::string::npos) { |
| 130 // Common case here is that mime_type is empty | 130 // Common case here is that mime_type is empty |
| 131 bool eq = !mime_type->empty() && | 131 bool eq = !mime_type->empty() && |
| 132 base::LowerCaseEqualsASCII( | 132 base::LowerCaseEqualsASCII( |
| 133 base::StringPiece(begin + type_val, begin + type_end), | 133 base::StringPiece(begin + type_val, begin + type_end), |
| 134 mime_type->data()); | 134 mime_type->data()); |
| 135 if (!eq) { | 135 if (!eq) { |
| 136 mime_type->assign(begin + type_val, begin + type_end); | 136 *mime_type = base::ToLowerASCII( |
| 137 base::StringToLowerASCII(mime_type); | 137 base::StringPiece(begin + type_val, begin + type_end)); |
| 138 } | 138 } |
| 139 if ((!eq && *had_charset) || type_has_charset) { | 139 if ((!eq && *had_charset) || type_has_charset) { |
| 140 *had_charset = true; | 140 *had_charset = true; |
| 141 charset->assign(begin + charset_val, begin + charset_end); | 141 *charset = base::ToLowerASCII( |
| 142 base::StringToLowerASCII(charset); | 142 base::StringPiece(begin + charset_val, begin + charset_end)); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 // static | 147 // static |
| 148 // Parse the Range header according to RFC 2616 14.35.1 | 148 // Parse the Range header according to RFC 2616 14.35.1 |
| 149 // ranges-specifier = byte-ranges-specifier | 149 // ranges-specifier = byte-ranges-specifier |
| 150 // byte-ranges-specifier = bytes-unit "=" byte-range-set | 150 // byte-ranges-specifier = bytes-unit "=" byte-range-set |
| 151 // byte-range-set = 1#( byte-range-spec | suffix-byte-range-spec ) | 151 // byte-range-set = 1#( byte-range-spec | suffix-byte-range-spec ) |
| 152 // byte-range-spec = first-byte-pos "-" [last-byte-pos] | 152 // byte-range-spec = first-byte-pos "-" [last-byte-pos] |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 "trailer", | 314 "trailer", |
| 315 "transfer-encoding", | 315 "transfer-encoding", |
| 316 "upgrade", | 316 "upgrade", |
| 317 "user-agent", | 317 "user-agent", |
| 318 "via", | 318 "via", |
| 319 }; | 319 }; |
| 320 } // anonymous namespace | 320 } // anonymous namespace |
| 321 | 321 |
| 322 // static | 322 // static |
| 323 bool HttpUtil::IsSafeHeader(const std::string& name) { | 323 bool HttpUtil::IsSafeHeader(const std::string& name) { |
| 324 std::string lower_name(base::StringToLowerASCII(name)); | 324 std::string lower_name(base::ToLowerASCII(name)); |
| 325 if (base::StartsWith(lower_name, "proxy-", base::CompareCase::SENSITIVE) || | 325 if (base::StartsWith(lower_name, "proxy-", base::CompareCase::SENSITIVE) || |
| 326 base::StartsWith(lower_name, "sec-", base::CompareCase::SENSITIVE)) | 326 base::StartsWith(lower_name, "sec-", base::CompareCase::SENSITIVE)) |
| 327 return false; | 327 return false; |
| 328 for (size_t i = 0; i < arraysize(kForbiddenHeaderFields); ++i) { | 328 for (size_t i = 0; i < arraysize(kForbiddenHeaderFields); ++i) { |
| 329 if (lower_name == kForbiddenHeaderFields[i]) | 329 if (lower_name == kForbiddenHeaderFields[i]) |
| 330 return false; | 330 return false; |
| 331 } | 331 } |
| 332 return true; | 332 return true; |
| 333 } | 333 } |
| 334 | 334 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 TrimLWS(&values_begin_, &values_end_); | 814 TrimLWS(&values_begin_, &values_end_); |
| 815 | 815 |
| 816 // if we got a header name, then we are done. | 816 // if we got a header name, then we are done. |
| 817 return true; | 817 return true; |
| 818 } | 818 } |
| 819 return false; | 819 return false; |
| 820 } | 820 } |
| 821 | 821 |
| 822 bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { | 822 bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { |
| 823 DCHECK(name != NULL); | 823 DCHECK(name != NULL); |
| 824 DCHECK_EQ(0, base::StringToLowerASCII<std::string>(name).compare(name)) | 824 DCHECK_EQ(0, base::ToLowerASCII(name).compare(name)) |
| 825 << "the header name must be in all lower case"; | 825 << "the header name must be in all lower case"; |
| 826 | 826 |
| 827 while (GetNext()) { | 827 while (GetNext()) { |
| 828 if (base::LowerCaseEqualsASCII(base::StringPiece(name_begin_, name_end_), | 828 if (base::LowerCaseEqualsASCII(base::StringPiece(name_begin_, name_end_), |
| 829 name)) { | 829 name)) { |
| 830 return true; | 830 return true; |
| 831 } | 831 } |
| 832 } | 832 } |
| 833 | 833 |
| 834 return false; | 834 return false; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 value_is_quoted_ = true; | 941 value_is_quoted_ = true; |
| 942 // Do not store iterators into this. See declaration of unquoted_value_. | 942 // Do not store iterators into this. See declaration of unquoted_value_. |
| 943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
| 944 } | 944 } |
| 945 } | 945 } |
| 946 | 946 |
| 947 return true; | 947 return true; |
| 948 } | 948 } |
| 949 | 949 |
| 950 } // namespace net | 950 } // namespace net |
| OLD | NEW |