| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 107 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 108 CHECK(!callback.is_null()); | 108 CHECK(!callback.is_null()); |
| 109 if (stream_closed_) | 109 if (stream_closed_) |
| 110 return closed_stream_status_; | 110 return closed_stream_status_; |
| 111 | 111 |
| 112 CHECK(stream_.get()); | 112 CHECK(stream_.get()); |
| 113 | 113 |
| 114 // Check if we already have the response headers. If so, return synchronously. | 114 // Check if we already have the response headers. If so, return synchronously. |
| 115 if(stream_->response_received()) { | 115 if(stream_->ReceivedInitialResponseHeaders()) { |
| 116 CHECK(stream_->is_idle()); | 116 CHECK(stream_->is_idle()); |
| 117 return OK; | 117 return OK; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Still waiting for the response, return IO_PENDING. | 120 // Still waiting for the response, return IO_PENDING. |
| 121 CHECK(callback_.is_null()); | 121 CHECK(callback_.is_null()); |
| 122 callback_ = callback; | 122 callback_ = callback; |
| 123 return ERR_IO_PENDING; | 123 return ERR_IO_PENDING; |
| 124 } | 124 } |
| 125 | 125 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 void SpdyHttpStream::OnRequestHeadersSent() { | 291 void SpdyHttpStream::OnRequestHeadersSent() { |
| 292 if (!callback_.is_null()) | 292 if (!callback_.is_null()) |
| 293 DoCallback(OK); | 293 DoCallback(OK); |
| 294 | 294 |
| 295 // TODO(akalin): Do this immediately after sending the request | 295 // TODO(akalin): Do this immediately after sending the request |
| 296 // headers. | 296 // headers. |
| 297 if (HasUploadData()) | 297 if (HasUploadData()) |
| 298 ReadAndSendRequestBodyData(); | 298 ReadAndSendRequestBodyData(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 int SpdyHttpStream::OnResponseHeadersReceived(const SpdyHeaderBlock& response, | 301 int SpdyHttpStream::OnResponseHeadersUpdated( |
| 302 base::Time response_time, | 302 const SpdyHeaderBlock& response_headers) { |
| 303 int status) { | |
| 304 if (!response_info_) { | 303 if (!response_info_) { |
| 305 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); | 304 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); |
| 306 push_response_info_.reset(new HttpResponseInfo); | 305 push_response_info_.reset(new HttpResponseInfo); |
| 307 response_info_ = push_response_info_.get(); | 306 response_info_ = push_response_info_.get(); |
| 308 } | 307 } |
| 309 | 308 |
| 310 // If the response is already received, these headers are too late. | 309 // If the response is already received, these headers are too late. |
| 311 if (response_headers_received_) { | 310 if (response_headers_received_) { |
| 312 LOG(WARNING) << "SpdyHttpStream headers received after response started."; | 311 LOG(WARNING) << "SpdyHttpStream headers received after response started."; |
| 313 return OK; | 312 return OK; |
| 314 } | 313 } |
| 315 | 314 |
| 316 // TODO(mbelshe): This is the time of all headers received, not just time | 315 if (!SpdyHeadersToHttpResponse( |
| 317 // to first byte. | 316 response_headers, stream_->GetProtocolVersion(), response_info_)) { |
| 318 response_info_->response_time = base::Time::Now(); | |
| 319 | |
| 320 if (!SpdyHeadersToHttpResponse(response, stream_->GetProtocolVersion(), | |
| 321 response_info_)) { | |
| 322 // We might not have complete headers yet. | 317 // We might not have complete headers yet. |
| 323 return ERR_INCOMPLETE_SPDY_HEADERS; | 318 return ERR_INCOMPLETE_SPDY_HEADERS; |
| 324 } | 319 } |
| 325 | 320 |
| 321 response_info_->response_time = stream_->response_time(); |
| 326 response_headers_received_ = true; | 322 response_headers_received_ = true; |
| 327 // Don't store the SSLInfo in the response here, HttpNetworkTransaction | 323 // Don't store the SSLInfo in the response here, HttpNetworkTransaction |
| 328 // will take care of that part. | 324 // will take care of that part. |
| 329 SSLInfo ssl_info; | 325 SSLInfo ssl_info; |
| 330 NextProto protocol_negotiated = kProtoUnknown; | 326 NextProto protocol_negotiated = kProtoUnknown; |
| 331 stream_->GetSSLInfo(&ssl_info, | 327 stream_->GetSSLInfo(&ssl_info, |
| 332 &response_info_->was_npn_negotiated, | 328 &response_info_->was_npn_negotiated, |
| 333 &protocol_negotiated); | 329 &protocol_negotiated); |
| 334 response_info_->npn_negotiated_protocol = | 330 response_info_->npn_negotiated_protocol = |
| 335 SSLClientSocket::NextProtoToString(protocol_negotiated); | 331 SSLClientSocket::NextProtoToString(protocol_negotiated); |
| 336 response_info_->request_time = stream_->GetRequestTime(); | 332 response_info_->request_time = stream_->GetRequestTime(); |
| 337 switch (spdy_session_->GetProtocolVersion()) { | 333 switch (spdy_session_->GetProtocolVersion()) { |
| 338 case SPDY2: | 334 case SPDY2: |
| 339 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY2; | 335 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY2; |
| 340 break; | 336 break; |
| 341 case SPDY3: | 337 case SPDY3: |
| 342 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY3; | 338 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY3; |
| 343 break; | 339 break; |
| 344 case SPDY4: | 340 case SPDY4: |
| 345 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY4; | 341 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_SPDY4; |
| 346 break; | 342 break; |
| 347 default: | 343 default: |
| 348 NOTREACHED(); | 344 NOTREACHED(); |
| 349 } | 345 } |
| 350 response_info_->vary_data | 346 response_info_->vary_data |
| 351 .Init(*request_info_, *response_info_->headers.get()); | 347 .Init(*request_info_, *response_info_->headers.get()); |
| 352 // TODO(ahendrickson): This is recorded after the entire SYN_STREAM control | |
| 353 // frame has been received and processed. Move to framer? | |
| 354 response_info_->response_time = response_time; | |
| 355 | 348 |
| 356 if (!callback_.is_null()) | 349 if (!callback_.is_null()) |
| 357 DoCallback(status); | 350 DoCallback(OK); |
| 358 | 351 |
| 359 return status; | 352 return OK; |
| 360 } | 353 } |
| 361 | 354 |
| 362 int SpdyHttpStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { | 355 int SpdyHttpStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { |
| 363 // SpdyStream won't call us with data if the header block didn't contain a | 356 // SpdyStream won't call us with data if the header block didn't contain a |
| 364 // valid set of headers. So we don't expect to not have headers received | 357 // valid set of headers. So we don't expect to not have headers received |
| 365 // here. | 358 // here. |
| 366 if (!response_headers_received_) | 359 if (!response_headers_received_) |
| 367 return ERR_INCOMPLETE_SPDY_HEADERS; | 360 return ERR_INCOMPLETE_SPDY_HEADERS; |
| 368 | 361 |
| 369 // Note that data may be received for a SpdyStream prior to the user calling | 362 // Note that data may be received for a SpdyStream prior to the user calling |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 bool SpdyHttpStream::IsSpdyHttpStream() const { | 539 bool SpdyHttpStream::IsSpdyHttpStream() const { |
| 547 return true; | 540 return true; |
| 548 } | 541 } |
| 549 | 542 |
| 550 void SpdyHttpStream::Drain(HttpNetworkSession* session) { | 543 void SpdyHttpStream::Drain(HttpNetworkSession* session) { |
| 551 Close(false); | 544 Close(false); |
| 552 delete this; | 545 delete this; |
| 553 } | 546 } |
| 554 | 547 |
| 555 } // namespace net | 548 } // namespace net |
| OLD | NEW |