| 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/quic/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_util.h" | 17 #include "net/http/http_util.h" |
| 18 #include "net/log/net_log_event_type.h" |
| 18 #include "net/quic/core/quic_client_promised_info.h" | 19 #include "net/quic/core/quic_client_promised_info.h" |
| 19 #include "net/quic/core/quic_http_utils.h" | 20 #include "net/quic/core/quic_http_utils.h" |
| 20 #include "net/quic/core/quic_utils.h" | 21 #include "net/quic/core/quic_utils.h" |
| 21 #include "net/quic/core/spdy_utils.h" | 22 #include "net/quic/core/spdy_utils.h" |
| 22 #include "net/spdy/spdy_frame_builder.h" | 23 #include "net/spdy/spdy_frame_builder.h" |
| 23 #include "net/spdy/spdy_framer.h" | 24 #include "net/spdy/spdy_framer.h" |
| 24 #include "net/spdy/spdy_http_utils.h" | 25 #include "net/spdy/spdy_http_utils.h" |
| 25 #include "net/ssl/ssl_info.h" | 26 #include "net/ssl/ssl_info.h" |
| 26 | 27 |
| 27 namespace net { | 28 namespace net { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (stream) { | 109 if (stream) { |
| 109 stream_ = static_cast<QuicChromiumClientStream*>(stream); | 110 stream_ = static_cast<QuicChromiumClientStream*>(stream); |
| 110 stream_->SetDelegate(this); | 111 stream_->SetDelegate(this); |
| 111 } | 112 } |
| 112 // callback_ should be non-null in the case of asynchronous | 113 // callback_ should be non-null in the case of asynchronous |
| 113 // rendezvous; i.e. |Try()| returned QUIC_PENDING. | 114 // rendezvous; i.e. |Try()| returned QUIC_PENDING. |
| 114 if (!callback_.is_null()) { | 115 if (!callback_.is_null()) { |
| 115 if (stream) { | 116 if (stream) { |
| 116 next_state_ = STATE_OPEN; | 117 next_state_ = STATE_OPEN; |
| 117 stream_net_log_.AddEvent( | 118 stream_net_log_.AddEvent( |
| 118 NetLog::TYPE_QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, | 119 NetLogEventType::QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, |
| 119 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), | 120 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), |
| 120 &request_info_->url)); | 121 &request_info_->url)); |
| 121 session_->net_log().AddEvent( | 122 session_->net_log().AddEvent( |
| 122 NetLog::TYPE_QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, | 123 NetLogEventType::QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, |
| 123 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), | 124 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), |
| 124 &request_info_->url)); | 125 &request_info_->url)); |
| 125 DoCallback(OK); | 126 DoCallback(OK); |
| 126 return; | 127 return; |
| 127 } | 128 } |
| 128 // rendezvous has failed so proceed as with a non-push request. | 129 // rendezvous has failed so proceed as with a non-push request. |
| 129 next_state_ = STATE_REQUEST_STREAM; | 130 next_state_ = STATE_REQUEST_STREAM; |
| 130 OnIOComplete(OK); | 131 OnIOComplete(OK); |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 134 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info, | 135 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info, |
| 135 RequestPriority priority, | 136 RequestPriority priority, |
| 136 const BoundNetLog& stream_net_log, | 137 const BoundNetLog& stream_net_log, |
| 137 const CompletionCallback& callback) { | 138 const CompletionCallback& callback) { |
| 138 CHECK(callback_.is_null()); | 139 CHECK(callback_.is_null()); |
| 139 DCHECK(!stream_); | 140 DCHECK(!stream_); |
| 140 if (!session_) | 141 if (!session_) |
| 141 return was_handshake_confirmed_ ? ERR_CONNECTION_CLOSED | 142 return was_handshake_confirmed_ ? ERR_CONNECTION_CLOSED |
| 142 : ERR_QUIC_HANDSHAKE_FAILED; | 143 : ERR_QUIC_HANDSHAKE_FAILED; |
| 143 | 144 |
| 144 stream_net_log.AddEvent( | 145 stream_net_log.AddEvent( |
| 145 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_QUIC_SESSION, | 146 NetLogEventType::HTTP_STREAM_REQUEST_BOUND_TO_QUIC_SESSION, |
| 146 session_->net_log().source().ToEventParametersCallback()); | 147 session_->net_log().source().ToEventParametersCallback()); |
| 147 | 148 |
| 148 stream_net_log_ = stream_net_log; | 149 stream_net_log_ = stream_net_log; |
| 149 request_info_ = request_info; | 150 request_info_ = request_info; |
| 150 request_time_ = base::Time::Now(); | 151 request_time_ = base::Time::Now(); |
| 151 priority_ = priority; | 152 priority_ = priority; |
| 152 | 153 |
| 153 bool success = session_->GetSSLInfo(&ssl_info_); | 154 bool success = session_->GetSSLInfo(&ssl_info_); |
| 154 DCHECK(success); | 155 DCHECK(success); |
| 155 DCHECK(ssl_info_.cert.get()); | 156 DCHECK(ssl_info_.cert.get()); |
| 156 | 157 |
| 157 std::string url(request_info->url.spec()); | 158 std::string url(request_info->url.spec()); |
| 158 QuicClientPromisedInfo* promised = | 159 QuicClientPromisedInfo* promised = |
| 159 session_->push_promise_index()->GetPromised(url); | 160 session_->push_promise_index()->GetPromised(url); |
| 160 if (promised) { | 161 if (promised) { |
| 161 found_promise_ = true; | 162 found_promise_ = true; |
| 162 stream_net_log_.AddEvent( | 163 stream_net_log_.AddEvent( |
| 163 NetLog::TYPE_QUIC_HTTP_STREAM_PUSH_PROMISE_RENDEZVOUS, | 164 NetLogEventType::QUIC_HTTP_STREAM_PUSH_PROMISE_RENDEZVOUS, |
| 164 base::Bind(&NetLogQuicPushStreamCallback, promised->id(), | 165 base::Bind(&NetLogQuicPushStreamCallback, promised->id(), |
| 165 &request_info_->url)); | 166 &request_info_->url)); |
| 166 session_->net_log().AddEvent( | 167 session_->net_log().AddEvent( |
| 167 NetLog::TYPE_QUIC_HTTP_STREAM_PUSH_PROMISE_RENDEZVOUS, | 168 NetLogEventType::QUIC_HTTP_STREAM_PUSH_PROMISE_RENDEZVOUS, |
| 168 base::Bind(&NetLogQuicPushStreamCallback, promised->id(), | 169 base::Bind(&NetLogQuicPushStreamCallback, promised->id(), |
| 169 &request_info_->url)); | 170 &request_info_->url)); |
| 170 return OK; | 171 return OK; |
| 171 } | 172 } |
| 172 | 173 |
| 173 next_state_ = STATE_REQUEST_STREAM; | 174 next_state_ = STATE_REQUEST_STREAM; |
| 174 int rv = DoLoop(OK); | 175 int rv = DoLoop(OK); |
| 175 if (rv == ERR_IO_PENDING) | 176 if (rv == ERR_IO_PENDING) |
| 176 callback_ = callback; | 177 callback_ = callback; |
| 177 | 178 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 218 |
| 218 switch (push_status) { | 219 switch (push_status) { |
| 219 case QUIC_FAILURE: | 220 case QUIC_FAILURE: |
| 220 // Push rendezvous failed. | 221 // Push rendezvous failed. |
| 221 next_state_ = STATE_REQUEST_STREAM; | 222 next_state_ = STATE_REQUEST_STREAM; |
| 222 break; | 223 break; |
| 223 case QUIC_SUCCESS: | 224 case QUIC_SUCCESS: |
| 224 next_state_ = STATE_OPEN; | 225 next_state_ = STATE_OPEN; |
| 225 if (!CancelPromiseIfHasBody()) { | 226 if (!CancelPromiseIfHasBody()) { |
| 226 stream_net_log_.AddEvent( | 227 stream_net_log_.AddEvent( |
| 227 NetLog::TYPE_QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, | 228 NetLogEventType::QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, |
| 228 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), | 229 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), |
| 229 &request_info_->url)); | 230 &request_info_->url)); |
| 230 session_->net_log().AddEvent( | 231 session_->net_log().AddEvent( |
| 231 NetLog::TYPE_QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, | 232 NetLogEventType::QUIC_HTTP_STREAM_ADOPTED_PUSH_STREAM, |
| 232 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), | 233 base::Bind(&NetLogQuicPushStreamCallback, stream_->id(), |
| 233 &request_info_->url)); | 234 &request_info_->url)); |
| 234 // Avoid the call to |DoLoop()| below, which would reset | 235 // Avoid the call to |DoLoop()| below, which would reset |
| 235 // next_state_ to STATE_NONE. | 236 // next_state_ to STATE_NONE. |
| 236 return OK; | 237 return OK; |
| 237 } | 238 } |
| 238 | 239 |
| 239 break; | 240 break; |
| 240 case QUIC_PENDING: | 241 case QUIC_PENDING: |
| 241 if (!CancelPromiseIfHasBody()) { | 242 if (!CancelPromiseIfHasBody()) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 next_state_ = STATE_SEND_HEADERS; | 684 next_state_ = STATE_SEND_HEADERS; |
| 684 return OK; | 685 return OK; |
| 685 } | 686 } |
| 686 | 687 |
| 687 int QuicHttpStream::DoSendHeaders() { | 688 int QuicHttpStream::DoSendHeaders() { |
| 688 if (!stream_) | 689 if (!stream_) |
| 689 return ERR_UNEXPECTED; | 690 return ERR_UNEXPECTED; |
| 690 | 691 |
| 691 // Log the actual request with the URL Request's net log. | 692 // Log the actual request with the URL Request's net log. |
| 692 stream_net_log_.AddEvent( | 693 stream_net_log_.AddEvent( |
| 693 NetLog::TYPE_HTTP_TRANSACTION_QUIC_SEND_REQUEST_HEADERS, | 694 NetLogEventType::HTTP_TRANSACTION_QUIC_SEND_REQUEST_HEADERS, |
| 694 base::Bind(&QuicRequestNetLogCallback, stream_->id(), &request_headers_, | 695 base::Bind(&QuicRequestNetLogCallback, stream_->id(), &request_headers_, |
| 695 priority_)); | 696 priority_)); |
| 696 bool has_upload_data = request_body_stream_ != nullptr; | 697 bool has_upload_data = request_body_stream_ != nullptr; |
| 697 | 698 |
| 698 next_state_ = STATE_SEND_HEADERS_COMPLETE; | 699 next_state_ = STATE_SEND_HEADERS_COMPLETE; |
| 699 size_t frame_len = stream_->WriteHeaders(std::move(request_headers_), | 700 size_t frame_len = stream_->WriteHeaders(std::move(request_headers_), |
| 700 !has_upload_data, nullptr); | 701 !has_upload_data, nullptr); |
| 701 headers_bytes_sent_ += frame_len; | 702 headers_bytes_sent_ += frame_len; |
| 702 | 703 |
| 703 request_headers_ = SpdyHeaderBlock(); | 704 request_headers_ = SpdyHeaderBlock(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 836 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 836 stream_ = nullptr; | 837 stream_ = nullptr; |
| 837 | 838 |
| 838 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress | 839 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress |
| 839 // read. | 840 // read. |
| 840 if (request_body_stream_) | 841 if (request_body_stream_) |
| 841 request_body_stream_->Reset(); | 842 request_body_stream_->Reset(); |
| 842 } | 843 } |
| 843 | 844 |
| 844 } // namespace net | 845 } // namespace net |
| OLD | NEW |