Commit dbe884a8 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Convert easy bits of HttpUtil to StringPiece.

Most of this file is awkwardly tied up with prtime.cc or
StringTokenizer, but convert some boring ones.

Bug: 820198
Change-Id: I339911e7cfbe6136a82d71ec1d1cd000ccc7b91a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1575873
Auto-Submit: David Benjamin <davidben@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Commit-Queue: David Benjamin <davidben@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652640}
parent 77f34eb1
...@@ -421,18 +421,18 @@ const char* const kForbiddenHeaderFields[] = { ...@@ -421,18 +421,18 @@ const char* const kForbiddenHeaderFields[] = {
} // namespace } // namespace
// static // static
bool HttpUtil::IsMethodSafe(const std::string& method) { bool HttpUtil::IsMethodSafe(base::StringPiece method) {
return method == "GET" || method == "HEAD" || method == "OPTIONS" || return method == "GET" || method == "HEAD" || method == "OPTIONS" ||
method == "TRACE"; method == "TRACE";
} }
// static // static
bool HttpUtil::IsMethodIdempotent(const std::string& method) { bool HttpUtil::IsMethodIdempotent(base::StringPiece method) {
return IsMethodSafe(method) || method == "PUT" || method == "DELETE"; return IsMethodSafe(method) || method == "PUT" || method == "DELETE";
} }
// static // static
bool HttpUtil::IsSafeHeader(const std::string& name) { bool HttpUtil::IsSafeHeader(base::StringPiece name) {
std::string lower_name(base::ToLowerASCII(name)); std::string lower_name(base::ToLowerASCII(name));
if (base::StartsWith(lower_name, "proxy-", base::CompareCase::SENSITIVE) || if (base::StartsWith(lower_name, "proxy-", base::CompareCase::SENSITIVE) ||
base::StartsWith(lower_name, "sec-", base::CompareCase::SENSITIVE)) base::StartsWith(lower_name, "sec-", base::CompareCase::SENSITIVE))
...@@ -446,13 +446,13 @@ bool HttpUtil::IsSafeHeader(const std::string& name) { ...@@ -446,13 +446,13 @@ bool HttpUtil::IsSafeHeader(const std::string& name) {
} }
// static // static
bool HttpUtil::IsValidHeaderName(const base::StringPiece& name) { bool HttpUtil::IsValidHeaderName(base::StringPiece name) {
// Check whether the header name is RFC 2616-compliant. // Check whether the header name is RFC 2616-compliant.
return HttpUtil::IsToken(name); return HttpUtil::IsToken(name);
} }
// static // static
bool HttpUtil::IsValidHeaderValue(const base::StringPiece& value) { bool HttpUtil::IsValidHeaderValue(base::StringPiece value) {
// Just a sanity check: disallow NUL, CR and LF. // Just a sanity check: disallow NUL, CR and LF.
for (char c : value) { for (char c : value) {
if (c == '\0' || c == '\r' || c == '\n') if (c == '\0' || c == '\r' || c == '\n')
......
...@@ -87,22 +87,22 @@ class NET_EXPORT HttpUtil { ...@@ -87,22 +87,22 @@ class NET_EXPORT HttpUtil {
// Returns true if the request method is "safe" (per section 4.2.1 of // Returns true if the request method is "safe" (per section 4.2.1 of
// RFC 7231). // RFC 7231).
static bool IsMethodSafe(const std::string& method); static bool IsMethodSafe(base::StringPiece method);
// Returns true if the request method is idempotent (per section 4.2.2 of // Returns true if the request method is idempotent (per section 4.2.2 of
// RFC 7231). // RFC 7231).
static bool IsMethodIdempotent(const std::string& method); static bool IsMethodIdempotent(base::StringPiece method);
// Returns true if it is safe to allow users and scripts to specify the header // Returns true if it is safe to allow users and scripts to specify the header
// named |name|. // named |name|.
static bool IsSafeHeader(const std::string& name); static bool IsSafeHeader(base::StringPiece name);
// Returns true if |name| is a valid HTTP header name. // Returns true if |name| is a valid HTTP header name.
static bool IsValidHeaderName(const base::StringPiece& name); static bool IsValidHeaderName(base::StringPiece name);
// Returns false if |value| contains NUL or CRLF. This method does not perform // Returns false if |value| contains NUL or CRLF. This method does not perform
// a fully RFC-2616-compliant header value validation. // a fully RFC-2616-compliant header value validation.
static bool IsValidHeaderValue(const base::StringPiece& value); static bool IsValidHeaderValue(base::StringPiece value);
// Multiple occurances of some headers cannot be coalesced into a comma- // Multiple occurances of some headers cannot be coalesced into a comma-
// separated list since their values are (or contain) unquoted HTTP-date // separated list since their values are (or contain) unquoted HTTP-date
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment