diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 00:29:14 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 00:29:14 +0000 |
commit | 2979a49a3c7582fd6ab07debf528e050b5437f9e (patch) | |
tree | 330ac4058fcc340c596ecdf7a3f3c52000c611dd /net | |
parent | bb56a37c7676803cb57a6be3174f9e2d0d5ba5e0 (diff) | |
download | chromium_src-2979a49a3c7582fd6ab07debf528e050b5437f9e.zip chromium_src-2979a49a3c7582fd6ab07debf528e050b5437f9e.tar.gz chromium_src-2979a49a3c7582fd6ab07debf528e050b5437f9e.tar.bz2 |
Move BuildRequestHeaders back to http_network_transaction.cc now that it's not needed by SPDY. This reduces the dependencies of http_util.cc and is a partial revert of r63213.
Review URL: http://codereview.chromium.org/6794038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_network_transaction.cc | 76 | ||||
-rw-r--r-- | net/http/http_network_transaction.h | 2 | ||||
-rw-r--r-- | net/http/http_util.cc | 97 | ||||
-rw-r--r-- | net/http/http_util.h | 17 |
4 files changed, 73 insertions, 119 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index d396c96..9271b33 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -677,6 +677,75 @@ int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { return rv; } +void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) { + request_headers_.SetHeader(HttpRequestHeaders::kHost, + GetHostAndOptionalPort(request_->url)); + + // For compat with HTTP/1.0 servers and proxies: + if (using_proxy) { + request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection, + "keep-alive"); + } else { + request_headers_.SetHeader(HttpRequestHeaders::kConnection, "keep-alive"); + } + + // Our consumer should have made sure that this is a safe referrer. See for + // instance WebCore::FrameLoader::HideReferrer. + if (request_->referrer.is_valid()) { + request_headers_.SetHeader(HttpRequestHeaders::kReferer, + request_->referrer.spec()); + } + + // Add a content length header? + if (request_body_.get()) { + if (request_body_->is_chunked()) { + request_headers_.SetHeader( + HttpRequestHeaders::kTransferEncoding, "chunked"); + } else { + request_headers_.SetHeader( + HttpRequestHeaders::kContentLength, + base::Uint64ToString(request_body_->size())); + } + } else if (request_->method == "POST" || request_->method == "PUT" || + request_->method == "HEAD") { + // An empty POST/PUT request still needs a content length. As for HEAD, + // IE and Safari also add a content length header. Presumably it is to + // support sending a HEAD request to an URL that only expects to be sent a + // POST or some other method that normally would have a message body. + request_headers_.SetHeader(HttpRequestHeaders::kContentLength, "0"); + } + + // Honor load flags that impact proxy caches. + if (request_->load_flags & LOAD_BYPASS_CACHE) { + request_headers_.SetHeader(HttpRequestHeaders::kPragma, "no-cache"); + request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "no-cache"); + } else if (request_->load_flags & LOAD_VALIDATE_CACHE) { + request_headers_.SetHeader(HttpRequestHeaders::kCacheControl, "max-age=0"); + } + + if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY)) + auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( + &request_headers_); + if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER)) + auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader( + &request_headers_); + + // Headers that will be stripped from request_->extra_headers to prevent, + // e.g., plugins from overriding headers that are controlled using other + // means. Otherwise a plugin could set a referrer although sending the + // referrer is inhibited. + // TODO(jochen): check whether also other headers should be stripped. + static const char* const kExtraHeadersToBeStripped[] = { + "Referer" + }; + + HttpRequestHeaders stripped_extra_headers; + stripped_extra_headers.CopyFrom(request_->extra_headers); + for (size_t i = 0; i < arraysize(kExtraHeadersToBeStripped); ++i) + stripped_extra_headers.RemoveHeader(kExtraHeadersToBeStripped[i]); + request_headers_.MergeFrom(stripped_extra_headers); +} + int HttpNetworkTransaction::DoBuildRequest() { next_state_ = STATE_BUILD_REQUEST_COMPLETE; delegate_callback_->AddRef(); // balanced in DoSendRequestComplete @@ -697,11 +766,7 @@ int HttpNetworkTransaction::DoBuildRequest() { if (request_headers_.IsEmpty()) { bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && !is_https_request(); - HttpUtil::BuildRequestHeaders(request_, request_body_.get(), - auth_controllers_, - ShouldApplyServerAuth(), - ShouldApplyProxyAuth(), using_proxy, - &request_headers_); + BuildRequestHeaders(using_proxy); } if (session_->network_delegate()) { @@ -1240,7 +1305,6 @@ bool HttpNetworkTransaction::HaveAuth(HttpAuth::Target target) const { auth_controllers_[target]->HaveAuth(); } - GURL HttpNetworkTransaction::AuthURL(HttpAuth::Target target) const { switch (target) { case HttpAuth::AUTH_PROXY: { diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index 414b1f9..00e9a65 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -138,6 +138,8 @@ class HttpNetworkTransaction : public HttpTransaction, int DoDrainBodyForAuthRestart(); int DoDrainBodyForAuthRestartComplete(int result); + void BuildRequestHeaders(bool using_proxy); + // Record histogram of time until first byte of header is received. void LogTransactionConnectedMetrics(); diff --git a/net/http/http_util.cc b/net/http/http_util.cc index fed74b6..f654a99 100644 --- a/net/http/http_util.cc +++ b/net/http/http_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,12 +14,6 @@ #include "base/string_number_conversions.h" #include "base/string_piece.h" #include "base/string_util.h" -#include "net/base/load_flags.h" -#include "net/base/net_util.h" -#include "net/base/upload_data_stream.h" -#include "net/http/http_request_info.h" -#include "net/http/http_request_headers.h" -#include "net/http/http_auth_controller.h" using std::string; @@ -636,95 +630,6 @@ HttpUtil::HeadersIterator::HeadersIterator(string::const_iterator headers_begin, : lines_(headers_begin, headers_end, line_delimiter) { } -namespace { - -bool HaveAuth(const scoped_refptr<HttpAuthController> auth_controllers[], - HttpAuth::Target target) { - return auth_controllers[target].get() && - auth_controllers[target]->HaveAuth(); -} - -} // namespace - -void HttpUtil::BuildRequestHeaders(const HttpRequestInfo* request_info, - const UploadDataStream* upload_data_stream, - const scoped_refptr<HttpAuthController> - auth_controllers[], - bool should_apply_server_auth, - bool should_apply_proxy_auth, - bool using_proxy, - HttpRequestHeaders* request_headers) { - request_headers->SetHeader(HttpRequestHeaders::kHost, - GetHostAndOptionalPort(request_info->url)); - - // For compat with HTTP/1.0 servers and proxies: - if (using_proxy) { - request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, - "keep-alive"); - } else { - request_headers->SetHeader(HttpRequestHeaders::kConnection, "keep-alive"); - } - - // Our consumer should have made sure that this is a safe referrer. See for - // instance WebCore::FrameLoader::HideReferrer. - if (request_info->referrer.is_valid()) { - request_headers->SetHeader(HttpRequestHeaders::kReferer, - request_info->referrer.spec()); - } - - // Add a content length header? - if (upload_data_stream) { - if (upload_data_stream->is_chunked()) { - request_headers->SetHeader( - HttpRequestHeaders::kTransferEncoding, "chunked"); - } else { - request_headers->SetHeader( - HttpRequestHeaders::kContentLength, - base::Uint64ToString(upload_data_stream->size())); - } - } else if (request_info->method == "POST" || request_info->method == "PUT" || - request_info->method == "HEAD") { - // An empty POST/PUT request still needs a content length. As for HEAD, - // IE and Safari also add a content length header. Presumably it is to - // support sending a HEAD request to an URL that only expects to be sent a - // POST or some other method that normally would have a message body. - request_headers->SetHeader(HttpRequestHeaders::kContentLength, "0"); - } - - // Honor load flags that impact proxy caches. - if (request_info->load_flags & LOAD_BYPASS_CACHE) { - request_headers->SetHeader(HttpRequestHeaders::kPragma, "no-cache"); - request_headers->SetHeader(HttpRequestHeaders::kCacheControl, "no-cache"); - } else if (request_info->load_flags & LOAD_VALIDATE_CACHE) { - request_headers->SetHeader(HttpRequestHeaders::kCacheControl, "max-age=0"); - } - - if (should_apply_proxy_auth && - HaveAuth(auth_controllers, HttpAuth::AUTH_PROXY)) - auth_controllers[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( - request_headers); - if (should_apply_server_auth && - HaveAuth(auth_controllers, HttpAuth::AUTH_SERVER)) - auth_controllers[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader( - request_headers); - - // Headers that will be stripped from request_info->extra_headers to prevent, - // e.g., plugins from overriding headers that are controlled using other - // means. Otherwise a plugin could set a referrer although sending the - // referrer is inhibited. - // TODO(jochen): check whether also other headers should be stripped. - static const char* const kExtraHeadersToBeStripped[] = { - "Referer" - }; - - HttpRequestHeaders stripped_extra_headers; - stripped_extra_headers.CopyFrom(request_info->extra_headers); - for (size_t i = 0; i < arraysize(kExtraHeadersToBeStripped); ++i) - stripped_extra_headers.RemoveHeader(kExtraHeadersToBeStripped[i]); - request_headers->MergeFrom(stripped_extra_headers); -} - - HttpUtil::HeadersIterator::~HeadersIterator() { } diff --git a/net/http/http_util.h b/net/http/http_util.h index 7f68e9d..91ea9c3 100644 --- a/net/http/http_util.h +++ b/net/http/http_util.h @@ -20,10 +20,6 @@ namespace net { -class HttpAuthController; -struct HttpRequestInfo; -class HttpRequestHeaders; -class HttpStream; class UploadDataStream; class HttpUtil { @@ -164,19 +160,6 @@ class HttpUtil { const std::string& header_value, std::string* headers); - // Constructs |request_headers| from the information contained in - // |request_info|. The correct server and proxy auth headers will - // be populated from |auth_controllers| if |enable_server_auth| or - // |enable_proxy_auth| is true. - static void BuildRequestHeaders(const HttpRequestInfo* request_info, - const UploadDataStream* upload_data_stream, - const scoped_refptr<HttpAuthController> - auth_controllers[], - bool enable_server_auth, - bool enable_proxy_auth, - bool enable_full_url, - HttpRequestHeaders* request_headers); - // Used to iterate over the name/value pairs of HTTP headers. To iterate // over the values in a multi-value header, use ValuesIterator. // See AssembleRawHeaders for joining line continuations (this iterator |