Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: net/http/http_util.cc

Issue 491123004: Make sure that HttpRequestHeaders contains valid key-value pairs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: edit comment Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
342 // static 342 // static
343 bool HttpUtil::IsValidHeaderName(const std::string& name) {
344 // Check whether the header name is RFC 2616-compliant.
345 return HttpUtil::IsToken(name);
346 }
347
348 // static
349 bool HttpUtil::IsValidHeaderValue(const std::string& value) {
350 // Just a sanity check: disallow NUL and CRLF.
351 return value.find('\0') == std::string::npos &&
352 value.find("\r\n") == std::string::npos;
353 }
354
355 // static
343 std::string HttpUtil::StripHeaders(const std::string& headers, 356 std::string HttpUtil::StripHeaders(const std::string& headers,
344 const char* const headers_to_remove[], 357 const char* const headers_to_remove[],
345 size_t headers_to_remove_len) { 358 size_t headers_to_remove_len) {
346 std::string stripped_headers; 359 std::string stripped_headers;
347 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 360 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
348 361
349 while (it.GetNext()) { 362 while (it.GetNext()) {
350 bool should_remove = false; 363 bool should_remove = false;
351 for (size_t i = 0; i < headers_to_remove_len; ++i) { 364 for (size_t i = 0; i < headers_to_remove_len; ++i) {
352 if (LowerCaseEqualsASCII(it.name_begin(), it.name_end(), 365 if (LowerCaseEqualsASCII(it.name_begin(), it.name_end(),
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 value_is_quoted_ = true; 911 value_is_quoted_ = true;
899 // Do not store iterators into this. See declaration of unquoted_value_. 912 // Do not store iterators into this. See declaration of unquoted_value_.
900 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 913 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
901 } 914 }
902 } 915 }
903 916
904 return true; 917 return true;
905 } 918 }
906 919
907 } // namespace net 920 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698