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

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: Use StringPiece. 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(base::StringPiece value) {
davidben 2015/09/30 16:38:18 Optional: Now that you have a base::StringPiece, I
hiroshige 2015/12/15 12:00:26 Done.
350 base::StringPiece::const_iterator value_begin = value.begin();
351 base::StringPiece::const_iterator value_end = value.end();
352
353 // Empty string is a valid header-value.
davidben 2015/09/30 16:38:18 Nit: "This empty string is a valid header-value.
hiroshige 2015/12/15 12:00:26 Done.
354 if (value_begin == value_end)
355 return true;
356
357 // Check leading/trailing whitespaces.
358 if (IsLWS(*value_begin) || IsLWS(*(value_end - 1)))
359 return false;
360
361 // Check each octet is |field-vchar|, |SP| or |HTAB|.
362 for (; value_begin != value_end; ++value_begin) {
363 unsigned char c = *value_begin;
364 if (c == 0x7F || c > 0xFF || (c < 0x20 && c != '\t'))
davidben 2015/09/30 16:38:18 c > 0xFF isn't possible. char's are one byte.
hiroshige 2015/12/15 12:00:26 Done.
365 return false;
366 }
367 return true;
368 }
369
370 // static
349 std::string HttpUtil::StripHeaders(const std::string& headers, 371 std::string HttpUtil::StripHeaders(const std::string& headers,
350 const char* const headers_to_remove[], 372 const char* const headers_to_remove[],
351 size_t headers_to_remove_len) { 373 size_t headers_to_remove_len) {
352 std::string stripped_headers; 374 std::string stripped_headers;
353 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); 375 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n");
354 376
355 while (it.GetNext()) { 377 while (it.GetNext()) {
356 bool should_remove = false; 378 bool should_remove = false;
357 for (size_t i = 0; i < headers_to_remove_len; ++i) { 379 for (size_t i = 0; i < headers_to_remove_len; ++i) {
358 if (base::LowerCaseEqualsASCII( 380 if (base::LowerCaseEqualsASCII(
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 value_is_quoted_ = true; 963 value_is_quoted_ = true;
942 // Do not store iterators into this. See declaration of unquoted_value_. 964 // Do not store iterators into this. See declaration of unquoted_value_.
943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 965 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
944 } 966 }
945 } 967 }
946 968
947 return true; 969 return true;
948 } 970 }
949 971
950 } // namespace net 972 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698