diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 20:42:12 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 20:42:12 +0000 |
commit | ee1a29b05d2e42c596d83ab862af8ec72e99a805 (patch) | |
tree | 08f3d8f63891bac3710d155743543098c87ff09a /chrome/browser | |
parent | f3a696be8b7b99ab44a2c7fb3e5945f1ee45e30d (diff) | |
download | chromium_src-ee1a29b05d2e42c596d83ab862af8ec72e99a805.zip chromium_src-ee1a29b05d2e42c596d83ab862af8ec72e99a805.tar.gz chromium_src-ee1a29b05d2e42c596d83ab862af8ec72e99a805.tar.bz2 |
Use net::HttpRequestHeaders instead of std::string in URLRequest and friends.
BUG=22588
Review URL: http://codereview.chromium.org/1998001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
3 files changed, 24 insertions, 17 deletions
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc index 8e8fd32..be0b57e 100644 --- a/chrome/browser/automation/url_request_automation_job.cc +++ b/chrome/browser/automation/url_request_automation_job.cc @@ -15,6 +15,7 @@ #include "net/base/cookie_monster.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" +#include "net/http/http_request_headers.h" #include "net/http/http_util.h" #include "net/url_request/url_request_context.h" @@ -23,7 +24,7 @@ using base::TimeDelta; // The list of filtered headers that are removed from requests sent via // StartAsync(). These must be lower case. -static const char* kFilteredHeaderStrings[] = { +static const char* const kFilteredHeaderStrings[] = { "accept", "cache-control", "connection", @@ -387,20 +388,26 @@ void URLRequestAutomationJob::StartAsync() { message_filter_->RegisterRequest(this); // Strip unwanted headers. - std::string new_request_headers( - net::HttpUtil::StripHeaders(request_->extra_request_headers(), - kFilteredHeaderStrings, - arraysize(kFilteredHeaderStrings))); + net::HttpRequestHeaders new_request_headers; + new_request_headers.MergeFrom(request_->extra_request_headers()); + for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i) + new_request_headers.RemoveHeader(kFilteredHeaderStrings[i]); if (request_->context()) { // Only add default Accept-Language and Accept-Charset if the request // didn't have them specified. - net::HttpUtil::AppendHeaderIfMissing( - "Accept-Language", request_->context()->accept_language(), - &new_request_headers); - net::HttpUtil::AppendHeaderIfMissing( - "Accept-Charset", request_->context()->accept_charset(), - &new_request_headers); + if (!new_request_headers.HasHeader( + net::HttpRequestHeaders::kAcceptLanguage) && + !request_->context()->accept_language().empty()) { + new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage, + request_->context()->accept_language()); + } + if (!new_request_headers.HasHeader( + net::HttpRequestHeaders::kAcceptCharset) && + !request_->context()->accept_charset().empty()) { + new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, + request_->context()->accept_charset()); + } } // Ensure that we do not send username and password fields in the referrer. @@ -419,7 +426,7 @@ void URLRequestAutomationJob::StartAsync() { request_->url().spec(), request_->method(), referrer.spec(), - new_request_headers, + new_request_headers.ToString(), request_->get_upload() }; diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 357a826..4c73634 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -1120,7 +1120,7 @@ int ResourceDispatcherHost::CalculateApproximateMemoryCost( // The following fields should be a minor size contribution (experimentally // on the order of 100). However since they are variable length, it could // in theory be a sizeable contribution. - int strings_cost = request->extra_request_headers().size() + + int strings_cost = request->extra_request_headers().ToString().size() + request->original_url().spec().size() + request->referrer().size() + request->method().size(); diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc index 097ad9ca..ef133b2 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -648,11 +648,11 @@ TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { // Test the private helper method "CalculateApproximateMemoryCost()". TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { URLRequest req(GURL("http://www.google.com"), NULL); - EXPECT_EQ(4425, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); + EXPECT_EQ(4427, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); // Add 9 bytes of referrer. req.set_referrer("123456789"); - EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); + EXPECT_EQ(4436, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); // Add 33 bytes of upload content. std::string upload_content; @@ -661,11 +661,11 @@ TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { req.AppendBytesToUpload(upload_content.data(), upload_content.size()); // Since the upload throttling is disabled, this has no effect on the cost. - EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); + EXPECT_EQ(4436, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); // Add a file upload -- should have no effect. req.AppendFileToUpload(FilePath(FILE_PATH_LITERAL("does-not-exist.png"))); - EXPECT_EQ(4434, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); + EXPECT_EQ(4436, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); } // Test the private helper method "IncrementOutstandingRequestsMemoryCost()". |