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

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

Issue 1374883002: Add UMAs for checking header values against RFC 7230 in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 340
341 // static 341 // static
342 bool HttpUtil::IsValidHeaderValue(const std::string& value) { 342 bool HttpUtil::IsValidHeaderValue(const std::string& value) {
343 // Just a sanity check: disallow NUL and CRLF. 343 // Just a sanity check: disallow NUL and CRLF.
344 return value.find('\0') == std::string::npos && 344 return value.find('\0') == std::string::npos &&
345 value.find("\r\n") == std::string::npos; 345 value.find("\r\n") == std::string::npos;
346 } 346 }
347 347
348 // static 348 // static
349 bool HttpUtil::IsValidHeaderValueRFC7230(const std::string& value) {
350 return IsValidHeaderValueRFC7230(value.begin(), value.end());
351 }
352
353 // static
354 bool HttpUtil::IsValidHeaderValueRFC7230(
355 std::string::const_iterator value_begin,
356 std::string::const_iterator value_end) {
357 // Empty string is a valid header-value.
358 if (value_begin == value_end)
359 return true;
360
361 // Check leading/trailing whitespaces.
362 if (IsLWS(*value_begin) || IsLWS(*(value_end - 1)))
363 return false;
364
365 // Check each octet is |field-vchar|, |SP| or |HTAB|.
366 for (; value_begin != value_end; ++value_begin) {
367 unsigned char c = *value_begin;
368 if (c == 0x7F || c > 0xFF || (c < 0x20 && c != '\t'))
369 return false;
370 }
371 return true;
372 }
373
374 // static
349 std::string HttpUtil::StripHeaders(const std::string& headers, 375 std::string HttpUtil::StripHeaders(const std::string& headers,
350 const char* const headers_to_remove[], 376 const char* const headers_to_remove[],
351 size_t headers_to_remove_len) { 377 size_t headers_to_remove_len) {
352 std::string stripped_headers; 378 std::string stripped_headers;
353 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 379 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
354 380
355 while (it.GetNext()) { 381 while (it.GetNext()) {
356 bool should_remove = false; 382 bool should_remove = false;
357 for (size_t i = 0; i < headers_to_remove_len; ++i) { 383 for (size_t i = 0; i < headers_to_remove_len; ++i) {
358 if (base::LowerCaseEqualsASCII( 384 if (base::LowerCaseEqualsASCII(
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 value_is_quoted_ = true; 967 value_is_quoted_ = true;
942 // Do not store iterators into this. See declaration of unquoted_value_. 968 // Do not store iterators into this. See declaration of unquoted_value_.
943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 969 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
944 } 970 }
945 } 971 }
946 972
947 return true; 973 return true;
948 } 974 }
949 975
950 } // namespace net 976 } // namespace net
OLDNEW
« net/http/http_util.h ('K') | « net/http/http_util.h ('k') | net/http/http_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698