| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // include a comma, so this check makes us a bit more tolerant. | 158 // include a comma, so this check makes us a bit more tolerant. |
| 159 if (content_type_str.length() != 0 && | 159 if (content_type_str.length() != 0 && |
| 160 content_type_str != "*/*" && | 160 content_type_str != "*/*" && |
| 161 content_type_str.find_first_of('/') != std::string::npos) { | 161 content_type_str.find_first_of('/') != std::string::npos) { |
| 162 // Common case here is that mime_type is empty | 162 // Common case here is that mime_type is empty |
| 163 bool eq = !mime_type->empty() && LowerCaseEqualsASCII(begin + type_val, | 163 bool eq = !mime_type->empty() && LowerCaseEqualsASCII(begin + type_val, |
| 164 begin + type_end, | 164 begin + type_end, |
| 165 mime_type->data()); | 165 mime_type->data()); |
| 166 if (!eq) { | 166 if (!eq) { |
| 167 mime_type->assign(begin + type_val, begin + type_end); | 167 mime_type->assign(begin + type_val, begin + type_end); |
| 168 StringToLowerASCII(mime_type); | 168 base::StringToLowerASCII(mime_type); |
| 169 } | 169 } |
| 170 if ((!eq && *had_charset) || type_has_charset) { | 170 if ((!eq && *had_charset) || type_has_charset) { |
| 171 *had_charset = true; | 171 *had_charset = true; |
| 172 charset->assign(begin + charset_val, begin + charset_end); | 172 charset->assign(begin + charset_val, begin + charset_end); |
| 173 StringToLowerASCII(charset); | 173 base::StringToLowerASCII(charset); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 // static | 178 // static |
| 179 // Parse the Range header according to RFC 2616 14.35.1 | 179 // Parse the Range header according to RFC 2616 14.35.1 |
| 180 // ranges-specifier = byte-ranges-specifier | 180 // ranges-specifier = byte-ranges-specifier |
| 181 // byte-ranges-specifier = bytes-unit "=" byte-range-set | 181 // byte-ranges-specifier = bytes-unit "=" byte-range-set |
| 182 // byte-range-set = 1#( byte-range-spec | suffix-byte-range-spec ) | 182 // byte-range-set = 1#( byte-range-spec | suffix-byte-range-spec ) |
| 183 // byte-range-spec = first-byte-pos "-" [last-byte-pos] | 183 // byte-range-spec = first-byte-pos "-" [last-byte-pos] |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 "trailer", | 321 "trailer", |
| 322 "transfer-encoding", | 322 "transfer-encoding", |
| 323 "upgrade", | 323 "upgrade", |
| 324 "user-agent", | 324 "user-agent", |
| 325 "via", | 325 "via", |
| 326 }; | 326 }; |
| 327 } // anonymous namespace | 327 } // anonymous namespace |
| 328 | 328 |
| 329 // static | 329 // static |
| 330 bool HttpUtil::IsSafeHeader(const std::string& name) { | 330 bool HttpUtil::IsSafeHeader(const std::string& name) { |
| 331 std::string lower_name(StringToLowerASCII(name)); | 331 std::string lower_name(base::StringToLowerASCII(name)); |
| 332 if (StartsWithASCII(lower_name, "proxy-", true) || | 332 if (StartsWithASCII(lower_name, "proxy-", true) || |
| 333 StartsWithASCII(lower_name, "sec-", true)) | 333 StartsWithASCII(lower_name, "sec-", true)) |
| 334 return false; | 334 return false; |
| 335 for (size_t i = 0; i < arraysize(kForbiddenHeaderFields); ++i) { | 335 for (size_t i = 0; i < arraysize(kForbiddenHeaderFields); ++i) { |
| 336 if (lower_name == kForbiddenHeaderFields[i]) | 336 if (lower_name == kForbiddenHeaderFields[i]) |
| 337 return false; | 337 return false; |
| 338 } | 338 } |
| 339 return true; | 339 return true; |
| 340 } | 340 } |
| 341 | 341 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 TrimLWS(&values_begin_, &values_end_); | 785 TrimLWS(&values_begin_, &values_end_); |
| 786 | 786 |
| 787 // if we got a header name, then we are done. | 787 // if we got a header name, then we are done. |
| 788 return true; | 788 return true; |
| 789 } | 789 } |
| 790 return false; | 790 return false; |
| 791 } | 791 } |
| 792 | 792 |
| 793 bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { | 793 bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { |
| 794 DCHECK(name != NULL); | 794 DCHECK(name != NULL); |
| 795 DCHECK_EQ(0, StringToLowerASCII<std::string>(name).compare(name)) | 795 DCHECK_EQ(0, base::StringToLowerASCII<std::string>(name).compare(name)) |
| 796 << "the header name must be in all lower case"; | 796 << "the header name must be in all lower case"; |
| 797 | 797 |
| 798 while (GetNext()) { | 798 while (GetNext()) { |
| 799 if (LowerCaseEqualsASCII(name_begin_, name_end_, name)) { | 799 if (LowerCaseEqualsASCII(name_begin_, name_end_, name)) { |
| 800 return true; | 800 return true; |
| 801 } | 801 } |
| 802 } | 802 } |
| 803 | 803 |
| 804 return false; | 804 return false; |
| 805 } | 805 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 value_is_quoted_ = true; | 898 value_is_quoted_ = true; |
| 899 // Do not store iterators into this. See declaration of unquoted_value_. | 899 // Do not store iterators into this. See declaration of unquoted_value_. |
| 900 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 900 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 | 903 |
| 904 return true; | 904 return true; |
| 905 } | 905 } |
| 906 | 906 |
| 907 } // namespace net | 907 } // namespace net |
| OLD | NEW |