Commit 0c8f2729 authored by tfarina's avatar tfarina Committed by Commit bot

net: remove AppendHeaderIfMissing() from HttpUtil

The last usage of this method was removed by commit 451a6636: ("rlz:
get rid of the call to AppendHeaderIfMissing()").

This also made possible to remove HasHeader() as AppendHeaderIfMissing()
were the only client of it.

With removing HasHeader() method from HttpUtil we fixed the Darin's
TODO.

BUG=488593
TEST=net_unittests
R=mmenke@chromium.org

Review-Url: https://codereview.chromium.org/2624213002
Cr-Commit-Position: refs/heads/master@{#442965}
parent 3fa98128
......@@ -312,30 +312,8 @@ bool HttpUtil::ParseRetryAfterHeader(const std::string& retry_after_string,
return true;
}
// static
bool HttpUtil::HasHeader(const std::string& headers, const char* name) {
size_t name_len = strlen(name);
std::string::const_iterator it =
std::search(headers.begin(),
headers.end(),
name,
name + name_len,
base::CaseInsensitiveCompareASCII<char>());
if (it == headers.end())
return false;
// ensure match is prefixed by newline
if (it != headers.begin() && it[-1] != '\n')
return false;
// ensure match is suffixed by colon
if (it + name_len >= headers.end() || it[name_len] != ':')
return false;
return true;
}
namespace {
// A header string containing any of the following fields will cause
// an error. The list comes from the XMLHttpRequest standard.
// http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
......@@ -362,7 +340,8 @@ const char* const kForbiddenHeaderFields[] = {
"user-agent",
"via",
};
} // anonymous namespace
} // namespace
// static
bool HttpUtil::IsSafeHeader(const std::string& name) {
......@@ -781,16 +760,6 @@ std::string HttpUtil::GenerateAcceptLanguageHeader(
return lang_list_with_q;
}
void HttpUtil::AppendHeaderIfMissing(const char* header_name,
const std::string& header_value,
std::string* headers) {
if (header_value.empty())
return;
if (HttpUtil::HasHeader(*headers, header_name))
return;
*headers += std::string(header_name) + ": " + header_value + "\r\n";
}
bool HttpUtil::HasStrongValidators(HttpVersion version,
const std::string& etag_header,
const std::string& last_modified_header,
......
......@@ -74,11 +74,6 @@ class NET_EXPORT HttpUtil {
base::Time now,
base::TimeDelta* retry_after);
// Scans the '\r\n'-delimited headers for the given header name. Returns
// true if a match is found. Input is assumed to be well-formed.
// TODO(darin): kill this
static bool HasHeader(const std::string& headers, const char* name);
// Returns true if it is safe to allow users and scripts to specify the header
// named |name|.
static bool IsSafeHeader(const std::string& name);
......@@ -210,12 +205,6 @@ class NET_EXPORT HttpUtil {
static std::string GenerateAcceptLanguageHeader(
const std::string& raw_language_list);
// Helper. If |*headers| already contains |header_name| do nothing,
// otherwise add <header_name> ": " <header_value> to the end of the list.
static void AppendHeaderIfMissing(const char* header_name,
const std::string& header_value,
std::string* headers);
// Returns true if the parameters describe a response with a strong etag or
// last-modified header. See section 13.3.3 of RFC 2616.
// An empty string should be passed for missing headers.
......
......@@ -100,26 +100,6 @@ TEST(HttpUtilTest, IsSafeHeader) {
}
}
TEST(HttpUtilTest, HasHeader) {
static const struct {
const char* const headers;
const char* const name;
bool expected_result;
} tests[] = {
{ "", "foo", false },
{ "foo\r\nbar", "foo", false },
{ "ffoo: 1", "foo", false },
{ "foo: 1", "foo", true },
{ "foo: 1\r\nbar: 2", "foo", true },
{ "fOO: 1\r\nbar: 2", "foo", true },
{ "g: 0\r\nfoo: 1\r\nbar: 2", "foo", true },
};
for (size_t i = 0; i < arraysize(tests); ++i) {
bool result = HttpUtil::HasHeader(tests[i].headers, tests[i].name);
EXPECT_EQ(tests[i].expected_result, result);
}
}
TEST(HttpUtilTest, HeadersIterator) {
std::string headers = "foo: 1\t\r\nbar: hello world\r\nbaz: 3 \r\n";
......
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