| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 response->headers = new net::HttpResponseHeaders(raw_headers); | 86 response->headers = new net::HttpResponseHeaders(raw_headers); |
| 87 response->was_fetched_via_spdy = true; | 87 response->was_fetched_via_spdy = true; |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Create a SpdyHeaderBlock for a Spdy SYN_STREAM Frame from | 91 // Create a SpdyHeaderBlock for a Spdy SYN_STREAM Frame from |
| 92 // a HttpRequestInfo block. | 92 // a HttpRequestInfo block. |
| 93 void CreateSpdyHeadersFromHttpRequest( | 93 void CreateSpdyHeadersFromHttpRequest( |
| 94 const net::HttpRequestInfo& info, spdy::SpdyHeaderBlock* headers) { | 94 const net::HttpRequestInfo& info, spdy::SpdyHeaderBlock* headers, |
| 95 bool direct) { |
| 95 // TODO(willchan): It's not really necessary to convert from | 96 // TODO(willchan): It's not really necessary to convert from |
| 96 // HttpRequestHeaders to spdy::SpdyHeaderBlock. | 97 // HttpRequestHeaders to spdy::SpdyHeaderBlock. |
| 97 | 98 |
| 98 static const char kHttpProtocolVersion[] = "HTTP/1.1"; | 99 static const char kHttpProtocolVersion[] = "HTTP/1.1"; |
| 99 | 100 |
| 100 net::HttpRequestHeaders::Iterator it(info.extra_headers); | 101 net::HttpRequestHeaders::Iterator it(info.extra_headers); |
| 101 | 102 |
| 102 while (it.GetNext()) { | 103 while (it.GetNext()) { |
| 103 std::string name = StringToLowerASCII(it.name()); | 104 std::string name = StringToLowerASCII(it.name()); |
| 104 if (headers->find(name) == headers->end()) { | 105 if (headers->find(name) == headers->end()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 base::Int64ToString(info.upload_data->GetContentLength()); | 125 base::Int64ToString(info.upload_data->GetContentLength()); |
| 125 } else if (info.method == "POST" || info.method == "PUT" || | 126 } else if (info.method == "POST" || info.method == "PUT" || |
| 126 info.method == "HEAD") { | 127 info.method == "HEAD") { |
| 127 // An empty POST/PUT request still needs a content length. As for HEAD, | 128 // An empty POST/PUT request still needs a content length. As for HEAD, |
| 128 // IE and Safari also add a content length header. Presumably it is to | 129 // IE and Safari also add a content length header. Presumably it is to |
| 129 // support sending a HEAD request to an URL that only expects to be sent a | 130 // support sending a HEAD request to an URL that only expects to be sent a |
| 130 // POST or some other method that normally would have a message body. | 131 // POST or some other method that normally would have a message body. |
| 131 (*headers)["content-length"] = "0"; | 132 (*headers)["content-length"] = "0"; |
| 132 } | 133 } |
| 133 | 134 |
| 134 (*headers)["url"] = net::HttpUtil::PathForRequest(info.url); | 135 if (direct) |
| 136 (*headers)["url"] = net::HttpUtil::PathForRequest(info.url); |
| 137 else |
| 138 (*headers)["url"] = net::HttpUtil::SpecForRequest(info.url); |
| 135 (*headers)["host"] = net::GetHostAndOptionalPort(info.url); | 139 (*headers)["host"] = net::GetHostAndOptionalPort(info.url); |
| 136 (*headers)["scheme"] = info.url.scheme(); | 140 (*headers)["scheme"] = info.url.scheme(); |
| 137 (*headers)["version"] = kHttpProtocolVersion; | 141 (*headers)["version"] = kHttpProtocolVersion; |
| 138 if (!info.referrer.is_empty()) | 142 if (!info.referrer.is_empty()) |
| 139 (*headers)["referer"] = info.referrer.spec(); | 143 (*headers)["referer"] = info.referrer.spec(); |
| 140 | 144 |
| 141 // Honor load flags that impact proxy caches. | 145 // Honor load flags that impact proxy caches. |
| 142 if (info.load_flags & net::LOAD_BYPASS_CACHE) { | 146 if (info.load_flags & net::LOAD_BYPASS_CACHE) { |
| 143 (*headers)["pragma"] = "no-cache"; | 147 (*headers)["pragma"] = "no-cache"; |
| 144 (*headers)["cache-control"] = "no-cache"; | 148 (*headers)["cache-control"] = "no-cache"; |
| 145 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { | 149 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { |
| 146 (*headers)["cache-control"] = "max-age=0"; | 150 (*headers)["cache-control"] = "max-age=0"; |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 } // anonymous namespace | 154 } // anonymous namespace |
| 151 | 155 |
| 152 namespace net { | 156 namespace net { |
| 153 | 157 |
| 154 SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session) | 158 SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, bool direct) |
| 155 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), | 159 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), |
| 156 stream_(NULL), | 160 stream_(NULL), |
| 157 spdy_session_(spdy_session), | 161 spdy_session_(spdy_session), |
| 158 response_info_(NULL), | 162 response_info_(NULL), |
| 159 download_finished_(false), | 163 download_finished_(false), |
| 160 user_callback_(NULL), | 164 user_callback_(NULL), |
| 161 user_buffer_len_(0), | 165 user_buffer_len_(0), |
| 162 buffered_read_callback_pending_(false), | 166 buffered_read_callback_pending_(false), |
| 163 more_read_data_pending_(false) { } | 167 more_read_data_pending_(false), |
| 168 direct_(direct) { } |
| 164 | 169 |
| 165 SpdyHttpStream::~SpdyHttpStream() { | 170 SpdyHttpStream::~SpdyHttpStream() { |
| 166 if (stream_) | 171 if (stream_) |
| 167 stream_->DetachDelegate(); | 172 stream_->DetachDelegate(); |
| 168 } | 173 } |
| 169 | 174 |
| 170 int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info, | 175 int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info, |
| 171 const BoundNetLog& stream_net_log, | 176 const BoundNetLog& stream_net_log, |
| 172 CompletionCallback* callback) { | 177 CompletionCallback* callback) { |
| 173 if (spdy_session_->IsClosed()) | 178 if (spdy_session_->IsClosed()) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/, | 277 int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/, |
| 273 UploadDataStream* request_body, | 278 UploadDataStream* request_body, |
| 274 HttpResponseInfo* response, | 279 HttpResponseInfo* response, |
| 275 CompletionCallback* callback) { | 280 CompletionCallback* callback) { |
| 276 base::Time request_time = base::Time::Now(); | 281 base::Time request_time = base::Time::Now(); |
| 277 CHECK(stream_.get()); | 282 CHECK(stream_.get()); |
| 278 | 283 |
| 279 stream_->SetDelegate(this); | 284 stream_->SetDelegate(this); |
| 280 | 285 |
| 281 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | 286 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); |
| 282 CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get()); | 287 CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get(), direct_); |
| 283 stream_->set_spdy_headers(headers); | 288 stream_->set_spdy_headers(headers); |
| 284 | 289 |
| 285 stream_->SetRequestTime(request_time); | 290 stream_->SetRequestTime(request_time); |
| 286 // This should only get called in the case of a request occurring | 291 // This should only get called in the case of a request occurring |
| 287 // during server push that has already begun but hasn't finished, | 292 // during server push that has already begun but hasn't finished, |
| 288 // so we set the response's request time to be the actual one | 293 // so we set the response's request time to be the actual one |
| 289 if (response_info_) | 294 if (response_info_) |
| 290 response_info_->request_time = request_time; | 295 response_info_->request_time = request_time; |
| 291 | 296 |
| 292 CHECK(!request_body_stream_.get()); | 297 CHECK(!request_body_stream_.get()); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 stream_->GetSSLInfo(ssl_info, &using_npn); | 510 stream_->GetSSLInfo(ssl_info, &using_npn); |
| 506 } | 511 } |
| 507 | 512 |
| 508 void SpdyHttpStream::GetSSLCertRequestInfo( | 513 void SpdyHttpStream::GetSSLCertRequestInfo( |
| 509 SSLCertRequestInfo* cert_request_info) { | 514 SSLCertRequestInfo* cert_request_info) { |
| 510 DCHECK(stream_); | 515 DCHECK(stream_); |
| 511 stream_->GetSSLCertRequestInfo(cert_request_info); | 516 stream_->GetSSLCertRequestInfo(cert_request_info); |
| 512 } | 517 } |
| 513 | 518 |
| 514 } // namespace net | 519 } // namespace net |
| OLD | NEW |