diff options
author | caseq@google.com <caseq@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 13:38:45 +0000 |
---|---|---|
committer | caseq@google.com <caseq@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 13:38:45 +0000 |
commit | 50ba404bc0cbfc6de3b7490cac5e60035ca62479 (patch) | |
tree | ba9daa52bab3a66f821b46da98247863f722ad1f /net/http | |
parent | fad4724ea22db25a776ddded782dbf0ee833f696 (diff) | |
download | chromium_src-50ba404bc0cbfc6de3b7490cac5e60035ca62479.zip chromium_src-50ba404bc0cbfc6de3b7490cac5e60035ca62479.tar.gz chromium_src-50ba404bc0cbfc6de3b7490cac5e60035ca62479.tar.bz2 |
Honor User-Agent header added by WebCore
- do not strip User-Agent while flattening headers in renderer
- do not override User-Agent header in the network stack if one is already supplied by higher level;
- added RequestHeaders::SetHeaderIfMissing
TEST=URLRequestTestHTTP.OverrideUserAgent
BUG=http://crbug.com/67063
Review URL=http://codereview.chromium.org/6065008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_request_headers.cc | 7 | ||||
-rw-r--r-- | net/http/http_request_headers.h | 6 | ||||
-rw-r--r-- | net/http/http_request_headers_unittest.cc | 8 |
3 files changed, 21 insertions, 0 deletions
diff --git a/net/http/http_request_headers.cc b/net/http/http_request_headers.cc index fc2ebcd..93ead01 100644 --- a/net/http/http_request_headers.cc +++ b/net/http/http_request_headers.cc @@ -76,6 +76,13 @@ void HttpRequestHeaders::Clear() { headers_.clear(); } +void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, + const base::StringPiece& value) { + HeaderVector::iterator it = FindHeader(key); + if (it == headers_.end()) + headers_.push_back(HeaderKeyValuePair(key.as_string(), value.as_string())); +} + void HttpRequestHeaders::SetHeader(const base::StringPiece& key, const base::StringPiece& value) { HeaderVector::iterator it = FindHeader(key); diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h index 734194a..2962ae2 100644 --- a/net/http/http_request_headers.h +++ b/net/http/http_request_headers.h @@ -95,6 +95,12 @@ class HttpRequestHeaders { // in the vector remains the same. When comparing |key|, case is ignored. void SetHeader(const base::StringPiece& key, const base::StringPiece& value); + // Sets the header value pair for |key| and |value|, if |key| does not exist. + // If |key| already exists, the call is a no-op. + // When comparing |key|, case is ignored. + void SetHeaderIfMissing(const base::StringPiece& key, + const base::StringPiece& value); + // Removes the first header that matches (case insensitive) |key|. void RemoveHeader(const base::StringPiece& key); diff --git a/net/http/http_request_headers_unittest.cc b/net/http/http_request_headers_unittest.cc index f3abfbe2..384ceeb 100644 --- a/net/http/http_request_headers_unittest.cc +++ b/net/http/http_request_headers_unittest.cc @@ -67,6 +67,14 @@ TEST(HttpRequestHeaders, SetEmptyHeader) { EXPECT_EQ("Foo: Bar\r\nBar:\r\n\r\n", headers.ToString()); } +TEST(HttpRequestHeaders, SetHeaderIfMissing) { + HttpRequestHeaders headers; + headers.SetHeaderIfMissing("Foo", "Bar"); + EXPECT_EQ("Foo: Bar\r\n\r\n", headers.ToString()); + headers.SetHeaderIfMissing("Foo", "Baz"); + EXPECT_EQ("Foo: Bar\r\n\r\n", headers.ToString()); +} + TEST(HttpRequestHeaders, RemoveHeader) { HttpRequestHeaders headers; headers.SetHeader("Foo", "bar"); |