summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 23:14:25 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 23:14:25 +0000
commit88e6b6f3251af7092432c33b7d372a17c7169904 (patch)
tree3fde374eed02ee05026449729952f0364609971b
parentda244100d3ac663a1f827fc712dc508c7761d207 (diff)
downloadchromium_src-88e6b6f3251af7092432c33b7d372a17c7169904.zip
chromium_src-88e6b6f3251af7092432c33b7d372a17c7169904.tar.gz
chromium_src-88e6b6f3251af7092432c33b7d372a17c7169904.tar.bz2
Pass HttpRequestHeaders to URLRequest::SetExtraRequestHeaders().
BUG=22588 Review URL: http://codereview.chromium.org/1998008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46752 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_plugin_host.cc5
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc4
-rw-r--r--chrome/common/net/url_fetcher.cc14
-rw-r--r--net/ocsp/nss_ocsp.cc17
-rw-r--r--net/url_request/url_request.cc12
-rw-r--r--net/url_request/url_request.h13
-rw-r--r--net/url_request/url_request_unittest.cc51
-rw-r--r--webkit/appcache/appcache_update_job.cc15
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.cc5
9 files changed, 76 insertions, 60 deletions
diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc
index f873fd5..c9b0428 100644
--- a/chrome/browser/chrome_plugin_host.cc
+++ b/chrome/browser/chrome_plugin_host.cc
@@ -41,6 +41,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/url_request/url_request_context.h"
#include "net/url_request/url_request_error_job.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -629,7 +630,9 @@ void STDCALL CPR_SetExtraRequestHeaders(CPRequest* request,
CHECK(ChromePluginLib::IsPluginThread());
PluginRequestHandler* handler = PluginRequestHandler::FromCPRequest(request);
CHECK(handler);
- handler->request()->SetExtraRequestHeaders(headers);
+ net::HttpRequestHeaders http_headers;
+ http_headers.AddHeadersFromString(headers);
+ handler->request()->SetExtraRequestHeaders(http_headers);
}
void STDCALL CPR_SetRequestLoadFlags(CPRequest* request, uint32 flags) {
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index 4c73634..2301720 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -396,7 +396,9 @@ void ResourceDispatcherHost::BeginRequest(
request->set_first_party_for_cookies(request_data.first_party_for_cookies);
request->set_referrer(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNoReferrers) ? std::string() : request_data.referrer.spec());
- request->SetExtraRequestHeaders(request_data.headers);
+ net::HttpRequestHeaders headers;
+ headers.AddHeadersFromString(request_data.headers);
+ request->SetExtraRequestHeaders(headers);
int load_flags = request_data.load_flags;
// EV certificate verification could be expensive. We don't want to spend
diff --git a/chrome/common/net/url_fetcher.cc b/chrome/common/net/url_fetcher.cc
index 042ff2f..c01eb6a 100644
--- a/chrome/common/net/url_fetcher.cc
+++ b/chrome/common/net/url_fetcher.cc
@@ -13,6 +13,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/load_flags.h"
#include "net/base/io_buffer.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
@@ -81,7 +82,7 @@ class URLFetcher::Core
scoped_refptr<URLRequestContextGetter> request_context_getter_;
// Cookie/cache info for the request
ResponseCookies cookies_; // Response cookies
- std::string extra_request_headers_;// Extra headers for the request, if any
+ net::HttpRequestHeaders extra_request_headers_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
std::string upload_content_; // HTTP POST payload
@@ -238,10 +239,8 @@ void URLFetcher::Core::StartURLRequest() {
DCHECK(!upload_content_type_.empty());
request_->set_method("POST");
- if (!extra_request_headers_.empty())
- extra_request_headers_ += "\r\n";
- StringAppendF(&extra_request_headers_,
- "Content-Type: %s", upload_content_type_.c_str());
+ extra_request_headers_.SetHeader(net::HttpRequestHeaders::kContentType,
+ upload_content_type_);
request_->AppendBytesToUpload(upload_content_.data(),
static_cast<int>(upload_content_.size()));
break;
@@ -254,7 +253,7 @@ void URLFetcher::Core::StartURLRequest() {
NOTREACHED();
}
- if (!extra_request_headers_.empty())
+ if (!extra_request_headers_.IsEmpty())
request_->SetExtraRequestHeaders(extra_request_headers_);
request_->Start();
@@ -332,7 +331,8 @@ int URLFetcher::load_flags() const {
void URLFetcher::set_extra_request_headers(
const std::string& extra_request_headers) {
- core_->extra_request_headers_ = extra_request_headers;
+ core_->extra_request_headers_.Clear();
+ core_->extra_request_headers_.AddHeadersFromString(extra_request_headers);
}
void URLFetcher::set_request_context(
diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc
index 3bb34c5..fa08801 100644
--- a/net/ocsp/nss_ocsp.cc
+++ b/net/ocsp/nss_ocsp.cc
@@ -23,6 +23,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
@@ -187,10 +188,8 @@ class OCSPRequestSession
}
void AddHeader(const char* http_header_name, const char* http_header_value) {
- if (!extra_request_headers_.empty())
- extra_request_headers_ += "\r\n";
- StringAppendF(&extra_request_headers_,
- "%s: %s", http_header_name, http_header_value);
+ extra_request_headers_.SetHeader(http_header_name,
+ http_header_value);
}
void Start() {
@@ -364,14 +363,12 @@ class OCSPRequestSession
DCHECK(!upload_content_type_.empty());
request_->set_method("POST");
- if (!extra_request_headers_.empty())
- extra_request_headers_ += "\r\n";
- StringAppendF(&extra_request_headers_,
- "Content-Type: %s", upload_content_type_.c_str());
+ extra_request_headers_.SetHeader(
+ net::HttpRequestHeaders::kContentType, upload_content_type_);
request_->AppendBytesToUpload(upload_content_.data(),
static_cast<int>(upload_content_.size()));
}
- if (!extra_request_headers_.empty())
+ if (!extra_request_headers_.IsEmpty())
request_->SetExtraRequestHeaders(extra_request_headers_);
request_->Start();
@@ -409,7 +406,7 @@ class OCSPRequestSession
base::TimeDelta timeout_; // The timeout for OCSP
URLRequest* request_; // The actual request this wraps
scoped_refptr<net::IOBuffer> buffer_; // Read buffer
- std::string extra_request_headers_; // Extra headers for the request, if any
+ net::HttpRequestHeaders extra_request_headers_;
std::string upload_content_; // HTTP POST payload
std::string upload_content_type_; // MIME type of POST payload
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 57ad3a3..701466e9a 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -137,16 +137,10 @@ void URLRequest::SetExtraRequestHeaderByName(const string& name,
NOTREACHED() << "implement me!";
}
-void URLRequest::SetExtraRequestHeaders(const string& headers) {
+void URLRequest::SetExtraRequestHeaders(
+ const net::HttpRequestHeaders& headers) {
DCHECK(!is_pending_);
- extra_request_headers_.Clear();
- if (!headers.empty()) {
-#ifndef NDEBUG
- size_t crlf = headers.rfind("\r\n", headers.size() - 1);
- DCHECK(crlf != headers.size() - 2) << "headers must not end with CRLF";
-#endif
- extra_request_headers_.AddHeadersFromString(headers);
- }
+ extra_request_headers_ = headers;
// NOTE: This method will likely become non-trivial once the other setters
// for request headers are implemented.
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index a31c6a2..250e4a2 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -328,15 +328,10 @@ class URLRequest {
void SetExtraRequestHeaderByName(const std::string& name,
const std::string& value, bool overwrite);
- // Sets all extra request headers, from a \r\n-delimited string. Any extra
- // request headers set by other methods are overwritten by this method. This
- // method may only be called before Start() is called. It is an error to
- // call it later.
- //
- // Note: \r\n is only used to separate the headers in the string if there
- // are multiple headers. The last header in the string must not be followed
- // by \r\n.
- void SetExtraRequestHeaders(const std::string& headers);
+ // Sets all extra request headers. Any extra request headers set by other
+ // methods are overwritten by this method. This method may only be called
+ // before Start() is called. It is an error to call it later.
+ void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers);
const net::HttpRequestHeaders& extra_request_headers() const {
return extra_request_headers_;
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 2cddb64..c90df21 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -36,6 +36,7 @@
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_layer.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/proxy/proxy_service.h"
#include "net/socket/ssl_test_util.h"
@@ -687,9 +688,11 @@ TEST_F(URLRequestTest, FileTestFullSpecifiedRange) {
{
TestURLRequest r(temp_url, &d);
- r.SetExtraRequestHeaders(
- StringPrintf("Range: bytes=%" PRIuS "-%" PRIuS "\n",
- first_byte_position, last_byte_position));
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kRange,
+ StringPrintf("bytes=%" PRIuS "-%" PRIuS,
+ first_byte_position, last_byte_position));
+ r.SetExtraRequestHeaders(headers);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -728,8 +731,11 @@ TEST_F(URLRequestTest, FileTestHalfSpecifiedRange) {
{
TestURLRequest r(temp_url, &d);
- r.SetExtraRequestHeaders(StringPrintf("Range: bytes=%" PRIuS "-\n",
- first_byte_position));
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kRange,
+ StringPrintf("bytes=%" PRIuS "-",
+ first_byte_position));
+ r.SetExtraRequestHeaders(headers);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -762,7 +768,10 @@ TEST_F(URLRequestTest, FileTestMultipleRanges) {
{
TestURLRequest r(temp_url, &d);
- r.SetExtraRequestHeaders(StringPrintf("Range: bytes=0-0,10-200,200-300\n"));
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kRange,
+ "bytes=0-0,10-200,200-300");
+ r.SetExtraRequestHeaders(headers);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -1092,7 +1101,9 @@ TEST_F(URLRequestTestHTTP, VaryHeader) {
TestDelegate d;
URLRequest req(server_->TestServerPage("echoheader?foo"), &d);
req.set_context(context);
- req.SetExtraRequestHeaders("foo: 1");
+ net::HttpRequestHeaders headers;
+ headers.SetHeader("foo", "1");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
}
@@ -1102,7 +1113,9 @@ TEST_F(URLRequestTestHTTP, VaryHeader) {
TestDelegate d;
URLRequest req(server_->TestServerPage("echoheader?foo"), &d);
req.set_context(context);
- req.SetExtraRequestHeaders("foo: 1");
+ net::HttpRequestHeaders headers;
+ headers.SetHeader("foo", "1");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
@@ -1114,7 +1127,9 @@ TEST_F(URLRequestTestHTTP, VaryHeader) {
TestDelegate d;
URLRequest req(server_->TestServerPage("echoheader?foo"), &d);
req.set_context(context);
- req.SetExtraRequestHeaders("foo: 2");
+ net::HttpRequestHeaders headers;
+ headers.SetHeader("foo", "2");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
@@ -1683,7 +1698,8 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
req.set_upload(CreateSimpleUploadData(kData));
// Set headers (some of which are specific to the POST).
- req.SetExtraRequestHeaders(
+ net::HttpRequestHeaders headers;
+ headers.AddHeadersFromString(
"Content-Type: multipart/form-data; "
"boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
@@ -1692,6 +1708,7 @@ TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
"Accept-Charset: ISO-8859-1,*,utf-8\r\n"
"Content-Length: 11\r\n"
"Origin: http://localhost:1337/");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
@@ -1720,8 +1737,10 @@ TEST_F(URLRequestTestHTTP, Post307RedirectPost) {
&d);
req.set_method("POST");
req.set_upload(CreateSimpleUploadData(kData).get());
- req.SetExtraRequestHeaders(
- "Content-Length: " + UintToString(sizeof(kData) - 1));
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kContentLength,
+ UintToString(arraysize(kData) - 1));
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
EXPECT_EQ("POST", req.method());
@@ -2492,7 +2511,9 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
TestURLRequest
req(server_->TestServerPage("echoheaderoverride?Accept-Language"), &d);
req.set_context(new TestURLRequestContext());
- req.SetExtraRequestHeaders("Accept-Language: ru");
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage, "ru");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
EXPECT_EQ(std::string("ru"), d.data_received());
@@ -2517,7 +2538,9 @@ TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) {
TestURLRequest
req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d);
req.set_context(new TestURLRequestContext());
- req.SetExtraRequestHeaders("Accept-Charset: koi-8r");
+ net::HttpRequestHeaders headers;
+ headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r");
+ req.SetExtraRequestHeaders(headers);
req.Start();
MessageLoop::current()->Run();
EXPECT_EQ(std::string("koi-8r"), d.data_received());
diff --git a/webkit/appcache/appcache_update_job.cc b/webkit/appcache/appcache_update_job.cc
index fb2fad1..dd2c79e 100644
--- a/webkit/appcache/appcache_update_job.cc
+++ b/webkit/appcache/appcache_update_job.cc
@@ -10,6 +10,7 @@
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
+#include "net/http/http_request_headers.h"
#include "webkit/appcache/appcache_group.h"
#include "webkit/appcache/appcache_policy.h"
#include "webkit/appcache/appcache_response.h"
@@ -274,15 +275,15 @@ void AppCacheUpdateJob::AddHttpHeadersAndFetch(
URLRequest* request, const net::HttpResponseInfo* info) {
DCHECK(request);
if (info) {
- std::string extra_headers;
+ net::HttpRequestHeaders extra_headers;
// Add If-Modified-Since header if response info has Last-Modified header.
const std::string last_modified = "Last-Modified";
std::string last_modified_value;
info->headers->EnumerateHeader(NULL, last_modified, &last_modified_value);
if (!last_modified_value.empty()) {
- extra_headers.append("If-Modified-Since: ");
- extra_headers.append(last_modified_value);
+ extra_headers.SetHeader(net::HttpRequestHeaders::kIfModifiedSince,
+ last_modified_value);
}
// Add If-None-Match header if resposne info has ETag header.
@@ -290,13 +291,11 @@ void AppCacheUpdateJob::AddHttpHeadersAndFetch(
std::string etag_value;
info->headers->EnumerateHeader(NULL, etag, &etag_value);
if (!etag_value.empty()) {
- if (!extra_headers.empty())
- extra_headers.append("\r\n");
- extra_headers.append("If-None-Match: ");
- extra_headers.append(etag_value);
+ extra_headers.SetHeader(net::HttpRequestHeaders::kIfNoneMatch,
+ etag_value);
}
- if (!extra_headers.empty())
+ if (!extra_headers.IsEmpty())
request->SetExtraRequestHeaders(extra_headers);
}
request->Start();
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index 5cfbea0..690f169 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -44,6 +44,7 @@
#include "net/base/net_util.h"
#include "net/base/static_cookie_policy.h"
#include "net/base/upload_data.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/proxy/proxy_service.h"
#include "net/url_request/url_request.h"
@@ -215,7 +216,9 @@ class RequestProxy : public URLRequest::Delegate,
request_->set_method(params->method);
request_->set_first_party_for_cookies(params->first_party_for_cookies);
request_->set_referrer(params->referrer.spec());
- request_->SetExtraRequestHeaders(params->headers);
+ net::HttpRequestHeaders headers;
+ headers.AddHeadersFromString(params->headers);
+ request_->SetExtraRequestHeaders(headers);
request_->set_load_flags(params->load_flags);
request_->set_upload(params->upload.get());
request_->set_context(request_context);