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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_util.cc
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index f1e5143e701a5334499dccc9a814ae4c96d2023b..16e32b57b9bf39bdccd2c30354773e4e8b173d31 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -346,6 +346,28 @@ bool HttpUtil::IsValidHeaderValue(const std::string& value) {
}
// static
+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.
+ base::StringPiece::const_iterator value_begin = value.begin();
+ base::StringPiece::const_iterator value_end = value.end();
+
+ // 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.
+ if (value_begin == value_end)
+ return true;
+
+ // Check leading/trailing whitespaces.
+ if (IsLWS(*value_begin) || IsLWS(*(value_end - 1)))
+ return false;
+
+ // Check each octet is |field-vchar|, |SP| or |HTAB|.
+ for (; value_begin != value_end; ++value_begin) {
+ unsigned char c = *value_begin;
+ 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.
+ return false;
+ }
+ return true;
+}
+
+// static
std::string HttpUtil::StripHeaders(const std::string& headers,
const char* const headers_to_remove[],
size_t headers_to_remove_len) {

Powered by Google App Engine
This is Rietveld 408576698