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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 346 } |
347 | 347 |
348 // static | 348 // static |
349 bool HttpUtil::IsValidHeaderValue(const std::string& value) { | 349 bool HttpUtil::IsValidHeaderValue(const std::string& value) { |
350 // Just a sanity check: disallow NUL and CRLF. | 350 // Just a sanity check: disallow NUL and CRLF. |
351 return value.find('\0') == std::string::npos && | 351 return value.find('\0') == std::string::npos && |
352 value.find("\r\n") == std::string::npos; | 352 value.find("\r\n") == std::string::npos; |
353 } | 353 } |
354 | 354 |
355 // static | 355 // static |
356 bool HttpUtil::IsValidHeaderValueRFC7230(const base::StringPiece& value) { | |
357 // This empty string is a valid header-value. | |
358 if (value.empty()) | |
359 return true; | |
360 | |
361 // Check leading/trailing whitespaces. | |
362 if (IsLWS(value[0]) || IsLWS(value[value.size() - 1])) | |
363 return false; | |
364 | |
365 // Check each octet is |field-vchar|, |SP| or |HTAB|. | |
366 for (unsigned char c : value) { | |
367 if (c == 0x7F || (c < 0x20 && c != '\t')) | |
368 return false; | |
369 } | |
370 return true; | |
371 } | |
372 | |
373 // static | |
374 std::string HttpUtil::StripHeaders(const std::string& headers, | 356 std::string HttpUtil::StripHeaders(const std::string& headers, |
375 const char* const headers_to_remove[], | 357 const char* const headers_to_remove[], |
376 size_t headers_to_remove_len) { | 358 size_t headers_to_remove_len) { |
377 std::string stripped_headers; | 359 std::string stripped_headers; |
378 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 360 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
379 | 361 |
380 while (it.GetNext()) { | 362 while (it.GetNext()) { |
381 bool should_remove = false; | 363 bool should_remove = false; |
382 for (size_t i = 0; i < headers_to_remove_len; ++i) { | 364 for (size_t i = 0; i < headers_to_remove_len; ++i) { |
383 if (base::LowerCaseEqualsASCII( | 365 if (base::LowerCaseEqualsASCII( |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 return true; | 1054 return true; |
1073 } | 1055 } |
1074 | 1056 |
1075 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const { | 1057 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const { |
1076 if (strict_quotes_) | 1058 if (strict_quotes_) |
1077 return c == '"'; | 1059 return c == '"'; |
1078 return HttpUtil::IsQuote(c); | 1060 return HttpUtil::IsQuote(c); |
1079 } | 1061 } |
1080 | 1062 |
1081 } // namespace net | 1063 } // namespace net |
OLD | NEW |