summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 15:33:52 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-20 15:33:52 +0000
commit7213e7cddc25d53822bd7bcad1e56b700ed0723a (patch)
treef2ad70306305b8baf875f8220eb33722ce9e9854 /net/spdy
parent54e6e79cce665b06c965d58852f0c6362b9ba567 (diff)
downloadchromium_src-7213e7cddc25d53822bd7bcad1e56b700ed0723a.zip
chromium_src-7213e7cddc25d53822bd7bcad1e56b700ed0723a.tar.gz
chromium_src-7213e7cddc25d53822bd7bcad1e56b700ed0723a.tar.bz2
Move BuildRequestHeaders from HttpNetworkTransaction to
HttpUtil::BuildRequestHeaders, so that it can be used directly by SpdyHttpStream, removing the code duplication. Strip proxy-connection header from SPDY requests to be consistent with Connection header. BUG=none TEST=none Review URL: http://codereview.chromium.org/3831005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_http_stream.cc6
-rw-r--r--net/spdy/spdy_http_utils.cc51
-rw-r--r--net/spdy/spdy_http_utils.h4
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc3
-rw-r--r--net/spdy/spdy_proxy_client_socket_unittest.cc2
-rw-r--r--net/spdy/spdy_test_util.cc1
6 files changed, 21 insertions, 46 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc
index 0e3962e..6fede6c 100644
--- a/net/spdy/spdy_http_stream.cc
+++ b/net/spdy/spdy_http_stream.cc
@@ -148,8 +148,12 @@ int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/,
stream_->SetDelegate(this);
+ HttpRequestHeaders request_headers;
+ HttpUtil::BuildRequestHeaders(request_info_, request_body, NULL, false, false,
+ !direct_, &request_headers);
linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock);
- CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get(), direct_);
+ CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers,
+ headers.get(), direct_);
stream_->set_spdy_headers(headers);
stream_->SetRequestTime(request_time);
diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc
index b2ef551..09ac79c 100644
--- a/net/spdy/spdy_http_utils.cc
+++ b/net/spdy/spdy_http_utils.cc
@@ -79,18 +79,16 @@ bool SpdyHeadersToHttpResponse(const spdy::SpdyHeaderBlock& headers,
return true;
}
-void CreateSpdyHeadersFromHttpRequest(
- const HttpRequestInfo& info, spdy::SpdyHeaderBlock* headers,
- bool direct) {
- // TODO(willchan): It's not really necessary to convert from
- // HttpRequestHeaders to spdy::SpdyHeaderBlock.
-
- static const char kHttpProtocolVersion[] = "HTTP/1.1";
-
- HttpRequestHeaders::Iterator it(info.extra_headers);
+void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
+ const HttpRequestHeaders& request_headers,
+ spdy::SpdyHeaderBlock* headers,
+ bool direct) {
+ HttpRequestHeaders::Iterator it(request_headers);
while (it.GetNext()) {
std::string name = StringToLowerASCII(it.name());
+ if (name == "connection" || name == "proxy-connection")
+ continue;
if (headers->find(name) == headers->end()) {
(*headers)[name] = it.value();
} else {
@@ -100,44 +98,17 @@ void CreateSpdyHeadersFromHttpRequest(
(*headers)[name] = new_value;
}
}
+ static const char kHttpProtocolVersion[] = "HTTP/1.1";
- // TODO(rch): Add Proxy headers here. (See http_network_transaction.cc)
- // TODO(rch): Add authentication headers here.
-
+ (*headers)["version"] = kHttpProtocolVersion;
(*headers)["method"] = info.method;
-
- // Handle content-length. This is the same as BuildRequestHeader in
- // http_network_transaction.cc.
- // TODO(lzheng): reduce the code duplication between spdy and http here.
- if (info.upload_data) {
- (*headers)["content-length"] =
- base::Int64ToString(info.upload_data->GetContentLength());
- } else if (info.method == "POST" || info.method == "PUT" ||
- 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.
- (*headers)["content-length"] = "0";
- }
-
+ (*headers)["host"] = GetHostAndOptionalPort(info.url);
+ (*headers)["scheme"] = info.url.scheme();
if (direct)
(*headers)["url"] = HttpUtil::PathForRequest(info.url);
else
(*headers)["url"] = HttpUtil::SpecForRequest(info.url);
- (*headers)["host"] = GetHostAndOptionalPort(info.url);
- (*headers)["scheme"] = info.url.scheme();
- (*headers)["version"] = kHttpProtocolVersion;
- if (!info.referrer.is_empty())
- (*headers)["referer"] = info.referrer.spec();
- // Honor load flags that impact proxy caches.
- if (info.load_flags & LOAD_BYPASS_CACHE) {
- (*headers)["pragma"] = "no-cache";
- (*headers)["cache-control"] = "no-cache";
- } else if (info.load_flags & LOAD_VALIDATE_CACHE) {
- (*headers)["cache-control"] = "max-age=0";
- }
}
} // namespace net
diff --git a/net/spdy/spdy_http_utils.h b/net/spdy/spdy_http_utils.h
index 7ec29a5..c6946dd 100644
--- a/net/spdy/spdy_http_utils.h
+++ b/net/spdy/spdy_http_utils.h
@@ -12,6 +12,7 @@ namespace net {
class HttpResponseInfo;
struct HttpRequestInfo;
+class HttpRequestHeaders;
// Convert a SpdyHeaderBlock into an HttpResponseInfo.
// |headers| input parameter with the SpdyHeaderBlock.
@@ -22,8 +23,9 @@ bool SpdyHeadersToHttpResponse(const spdy::SpdyHeaderBlock& headers,
HttpResponseInfo* response);
// Create a SpdyHeaderBlock for a Spdy SYN_STREAM Frame from
-// a HttpRequestInfo block.
+// HttpRequestInfo and HttpRequestHeaders.
void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info,
+ const HttpRequestHeaders& request_headers,
spdy::SpdyHeaderBlock* headers,
bool direct);
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index c8a0153..53bcb0d 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -312,7 +312,8 @@ int SpdyProxyClientSocket::DoSendRequest() {
request_.extra_headers.MergeFrom(request_headers);
linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock());
- CreateSpdyHeadersFromHttpRequest(request_, headers.get(), true);
+ CreateSpdyHeadersFromHttpRequest(request_, request_headers, headers.get(),
+ true);
// Reset the URL to be the endpoint of the connection
(*headers)["url"] = endpoint_.ToString();
headers->erase("scheme");
diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc
index 9639036..236713ac 100644
--- a/net/spdy/spdy_proxy_client_socket_unittest.cc
+++ b/net/spdy/spdy_proxy_client_socket_unittest.cc
@@ -311,7 +311,6 @@ spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRequestFrame() {
"host", kOriginHost,
"user-agent", kUserAgent,
"version", "HTTP/1.1",
- "proxy-connection", "keep-alive",
};
return ConstructSpdyPacket(
kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2);
@@ -339,7 +338,6 @@ spdy::SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() {
"user-agent", kUserAgent,
"version", "HTTP/1.1",
"proxy-authorization", "Basic Zm9vOmJhcg==",
- "proxy-connection", "keep-alive",
};
return ConstructSpdyPacket(
kSynStartHeader, NULL, 0, kConnectHeaders, arraysize(kConnectHeaders)/2);
diff --git a/net/spdy/spdy_test_util.cc b/net/spdy/spdy_test_util.cc
index 3dda1edd..d3b82c0c6 100644
--- a/net/spdy/spdy_test_util.cc
+++ b/net/spdy/spdy_test_util.cc
@@ -416,7 +416,6 @@ spdy::SpdyFrame* ConstructSpdyConnect(const char* const extra_headers[],
"url", "www.google.com:443",
"host", "www.google.com",
"version", "HTTP/1.1",
- "proxy-connection", "keep-alive",
};
return ConstructSpdyControlFrame(extra_headers,
extra_header_count,