| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 bool direct) | 35 bool direct) |
| 36 : spdy_session_(spdy_session), | 36 : spdy_session_(spdy_session), |
| 37 is_reused_(spdy_session_->IsReused()), | 37 is_reused_(spdy_session_->IsReused()), |
| 38 stream_closed_(false), | 38 stream_closed_(false), |
| 39 closed_stream_status_(ERR_FAILED), | 39 closed_stream_status_(ERR_FAILED), |
| 40 closed_stream_id_(0), | 40 closed_stream_id_(0), |
| 41 closed_stream_received_bytes_(0), | 41 closed_stream_received_bytes_(0), |
| 42 closed_stream_sent_bytes_(0), | 42 closed_stream_sent_bytes_(0), |
| 43 request_info_(NULL), | 43 request_info_(NULL), |
| 44 response_info_(NULL), | 44 response_info_(NULL), |
| 45 response_headers_status_(RESPONSE_HEADERS_ARE_INCOMPLETE), | 45 response_headers_complete_(false), |
| 46 user_buffer_len_(0), | 46 user_buffer_len_(0), |
| 47 request_body_buf_size_(0), | 47 request_body_buf_size_(0), |
| 48 buffered_read_callback_pending_(false), | 48 buffered_read_callback_pending_(false), |
| 49 more_read_data_pending_(false), | 49 more_read_data_pending_(false), |
| 50 direct_(direct), | 50 direct_(direct), |
| 51 was_alpn_negotiated_(false), | 51 was_alpn_negotiated_(false), |
| 52 weak_factory_(this) { | 52 weak_factory_(this) { |
| 53 DCHECK(spdy_session_.get()); | 53 DCHECK(spdy_session_.get()); |
| 54 } | 54 } |
| 55 | 55 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 100 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 101 CHECK(!callback.is_null()); | 101 CHECK(!callback.is_null()); |
| 102 if (stream_closed_) | 102 if (stream_closed_) |
| 103 return closed_stream_status_; | 103 return closed_stream_status_; |
| 104 | 104 |
| 105 CHECK(stream_.get()); | 105 CHECK(stream_.get()); |
| 106 | 106 |
| 107 // Check if we already have the response headers. If so, return synchronously. | 107 // Check if we already have the response headers. If so, return synchronously. |
| 108 if (response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { | 108 if (response_headers_complete_) { |
| 109 CHECK(!stream_->IsIdle()); | 109 CHECK(!stream_->IsIdle()); |
| 110 return OK; | 110 return OK; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Still waiting for the response, return IO_PENDING. | 113 // Still waiting for the response, return IO_PENDING. |
| 114 CHECK(response_callback_.is_null()); | 114 CHECK(response_callback_.is_null()); |
| 115 response_callback_ = callback; | 115 response_callback_ = callback; |
| 116 return ERR_IO_PENDING; | 116 return ERR_IO_PENDING; |
| 117 } | 117 } |
| 118 | 118 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 294 |
| 295 void SpdyHttpStream::Cancel() { | 295 void SpdyHttpStream::Cancel() { |
| 296 request_callback_.Reset(); | 296 request_callback_.Reset(); |
| 297 response_callback_.Reset(); | 297 response_callback_.Reset(); |
| 298 if (stream_.get()) { | 298 if (stream_.get()) { |
| 299 stream_->Cancel(); | 299 stream_->Cancel(); |
| 300 DCHECK(!stream_.get()); | 300 DCHECK(!stream_.get()); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 void SpdyHttpStream::OnRequestHeadersSent() { | 304 void SpdyHttpStream::OnHeadersSent() { |
| 305 if (HasUploadData()) { | 305 if (HasUploadData()) { |
| 306 ReadAndSendRequestBodyData(); | 306 ReadAndSendRequestBodyData(); |
| 307 } else { | 307 } else { |
| 308 MaybePostRequestCallback(OK); | 308 MaybePostRequestCallback(OK); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( | 312 void SpdyHttpStream::OnHeadersReceived( |
| 313 const SpdyHeaderBlock& response_headers) { | 313 const SpdyHeaderBlock& response_headers) { |
| 314 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); | 314 DCHECK(!response_headers_complete_); |
| 315 response_headers_complete_ = true; |
| 315 | 316 |
| 316 if (!response_info_) { | 317 if (!response_info_) { |
| 317 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); | 318 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); |
| 318 push_response_info_.reset(new HttpResponseInfo); | 319 push_response_info_.reset(new HttpResponseInfo); |
| 319 response_info_ = push_response_info_.get(); | 320 response_info_ = push_response_info_.get(); |
| 320 } | 321 } |
| 321 | 322 |
| 322 if (!SpdyHeadersToHttpResponse(response_headers, response_info_)) { | 323 const bool headers_valid = |
| 323 // We do not have complete headers yet. | 324 SpdyHeadersToHttpResponse(response_headers, response_info_); |
| 324 return RESPONSE_HEADERS_ARE_INCOMPLETE; | 325 DCHECK(headers_valid); |
| 325 } | |
| 326 | 326 |
| 327 response_info_->response_time = stream_->response_time(); | 327 response_info_->response_time = stream_->response_time(); |
| 328 response_headers_status_ = RESPONSE_HEADERS_ARE_COMPLETE; | |
| 329 // Don't store the SSLInfo in the response here, HttpNetworkTransaction | 328 // Don't store the SSLInfo in the response here, HttpNetworkTransaction |
| 330 // will take care of that part. | 329 // will take care of that part. |
| 331 response_info_->was_alpn_negotiated = was_alpn_negotiated_; | 330 response_info_->was_alpn_negotiated = was_alpn_negotiated_; |
| 332 response_info_->request_time = stream_->GetRequestTime(); | 331 response_info_->request_time = stream_->GetRequestTime(); |
| 333 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 332 response_info_->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
| 334 response_info_->alpn_negotiated_protocol = | 333 response_info_->alpn_negotiated_protocol = |
| 335 HttpResponseInfo::ConnectionInfoToString(response_info_->connection_info); | 334 HttpResponseInfo::ConnectionInfoToString(response_info_->connection_info); |
| 336 response_info_->vary_data | 335 response_info_->vary_data |
| 337 .Init(*request_info_, *response_info_->headers.get()); | 336 .Init(*request_info_, *response_info_->headers.get()); |
| 338 | 337 |
| 339 if (!response_callback_.is_null()) { | 338 if (!response_callback_.is_null()) { |
| 340 DoResponseCallback(OK); | 339 DoResponseCallback(OK); |
| 341 } | 340 } |
| 342 | |
| 343 return RESPONSE_HEADERS_ARE_COMPLETE; | |
| 344 } | 341 } |
| 345 | 342 |
| 346 void SpdyHttpStream::OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) { | 343 void SpdyHttpStream::OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) { |
| 347 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_COMPLETE); | 344 DCHECK(response_headers_complete_); |
| 348 | 345 |
| 349 // Note that data may be received for a SpdyStream prior to the user calling | 346 // Note that data may be received for a SpdyStream prior to the user calling |
| 350 // ReadResponseBody(), therefore user_buffer_ may be NULL. This may often | 347 // ReadResponseBody(), therefore user_buffer_ may be NULL. This may often |
| 351 // happen for server initiated streams. | 348 // happen for server initiated streams. |
| 352 DCHECK(stream_.get()); | 349 DCHECK(stream_.get()); |
| 353 DCHECK(!stream_->IsClosed() || stream_->type() == SPDY_PUSH_STREAM); | 350 DCHECK(!stream_->IsClosed() || stream_->type() == SPDY_PUSH_STREAM); |
| 354 if (buffer) { | 351 if (buffer) { |
| 355 response_body_queue_.Enqueue(std::move(buffer)); | 352 response_body_queue_.Enqueue(std::move(buffer)); |
| 356 | 353 |
| 357 if (user_buffer_.get()) { | 354 if (user_buffer_.get()) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 608 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
| 612 return; | 609 return; |
| 613 } | 610 } |
| 614 | 611 |
| 615 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 612 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
| 616 // TODO(akalin): Plumb this through to |stream_request_| and | 613 // TODO(akalin): Plumb this through to |stream_request_| and |
| 617 // |stream_|. | 614 // |stream_|. |
| 618 } | 615 } |
| 619 | 616 |
| 620 } // namespace net | 617 } // namespace net |
| OLD | NEW |