[email protected] | 5477d89 | 2012-03-01 21:31:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 5 | #include "net/http/http_stream_request.h" |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 6 | |
Bence Béky | 6d05ebd | 2017-05-16 00:09:01 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | b675425 | 2012-06-13 23:14:38 | [diff] [blame] | 9 | #include "base/callback.h" |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 11 | #include "base/stl_util.h" |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 12 | #include "net/http/bidirectional_stream_impl.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13 | #include "net/log/net_log_event_type.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 14 | #include "net/spdy/spdy_http_stream.h" |
| 15 | #include "net/spdy/spdy_session.h" |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 16 | |
| 17 | namespace net { |
| 18 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 19 | HttpStreamRequest::HttpStreamRequest( |
[email protected] | 3732cea | 2013-06-21 06:50:50 | [diff] [blame] | 20 | const GURL& url, |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 21 | Helper* helper, |
[email protected] | 3732cea | 2013-06-21 06:50:50 | [diff] [blame] | 22 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 23 | WebSocketHandshakeStreamBase::CreateHelper* |
| 24 | websocket_handshake_stream_create_helper, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 25 | const NetLogWithSource& net_log, |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 26 | StreamType stream_type) |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 27 | : url_(url), |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 28 | helper_(helper), |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 29 | websocket_handshake_stream_create_helper_( |
| 30 | websocket_handshake_stream_create_helper), |
[email protected] | 7b496b3 | 2011-02-28 22:25:59 | [diff] [blame] | 31 | net_log_(net_log), |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 32 | completed_(false), |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 33 | was_alpn_negotiated_(false), |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 34 | negotiated_protocol_(kProtoUnknown), |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 35 | using_spdy_(false), |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 36 | stream_type_(stream_type) { |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 37 | net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_REQUEST); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 38 | } |
| 39 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 40 | HttpStreamRequest::~HttpStreamRequest() { |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 41 | net_log_.EndEvent(NetLogEventType::HTTP_STREAM_REQUEST); |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 42 | helper_->OnRequestComplete(); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 43 | } |
| 44 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 45 | void HttpStreamRequest::Complete(bool was_alpn_negotiated, |
| 46 | NextProto negotiated_protocol, |
| 47 | bool using_spdy) { |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 48 | DCHECK(!completed_); |
| 49 | completed_ = true; |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 50 | was_alpn_negotiated_ = was_alpn_negotiated; |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 51 | negotiated_protocol_ = negotiated_protocol; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 52 | using_spdy_ = using_spdy; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 53 | } |
| 54 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 55 | void HttpStreamRequest::OnStreamReadyOnPooledConnection( |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 56 | const SSLConfig& used_ssl_config, |
| 57 | const ProxyInfo& used_proxy_info, |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 58 | std::unique_ptr<HttpStream> stream) { |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 59 | DCHECK(completed_); |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 60 | helper_->OnStreamReadyOnPooledConnection(used_ssl_config, used_proxy_info, |
| 61 | std::move(stream)); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 62 | } |
| 63 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 64 | void HttpStreamRequest::OnBidirectionalStreamImplReadyOnPooledConnection( |
| 65 | const SSLConfig& used_ssl_config, |
| 66 | const ProxyInfo& used_proxy_info, |
| 67 | std::unique_ptr<BidirectionalStreamImpl> stream) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 68 | DCHECK(completed_); |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 69 | helper_->OnBidirectionalStreamImplReadyOnPooledConnection( |
Bence Béky | fe7f0f48 | 2017-06-27 23:12:10 | [diff] [blame] | 70 | used_ssl_config, used_proxy_info, std::move(stream)); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 71 | } |
| 72 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 73 | int HttpStreamRequest::RestartTunnelWithProxyAuth() { |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 74 | return helper_->RestartTunnelWithProxyAuth(); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 75 | } |
| 76 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 77 | void HttpStreamRequest::SetPriority(RequestPriority priority) { |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 78 | helper_->SetPriority(priority); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 79 | } |
| 80 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 81 | LoadState HttpStreamRequest::GetLoadState() const { |
Helen Li | f62edf73 | 2017-08-23 22:25:18 | [diff] [blame] | 82 | return helper_->GetLoadState(); |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 83 | } |
| 84 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 85 | bool HttpStreamRequest::was_alpn_negotiated() const { |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 86 | DCHECK(completed_); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 87 | return was_alpn_negotiated_; |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 88 | } |
| 89 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 90 | NextProto HttpStreamRequest::negotiated_protocol() const { |
[email protected] | c30bcce | 2011-12-20 17:50:51 | [diff] [blame] | 91 | DCHECK(completed_); |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 92 | return negotiated_protocol_; |
[email protected] | c30bcce | 2011-12-20 17:50:51 | [diff] [blame] | 93 | } |
| 94 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 95 | bool HttpStreamRequest::using_spdy() const { |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 96 | DCHECK(completed_); |
| 97 | return using_spdy_; |
| 98 | } |
| 99 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 100 | const ConnectionAttempts& HttpStreamRequest::connection_attempts() const { |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 101 | return connection_attempts_; |
| 102 | } |
| 103 | |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 104 | void HttpStreamRequest::AddConnectionAttempts( |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 105 | const ConnectionAttempts& attempts) { |
| 106 | for (const auto& attempt : attempts) |
| 107 | connection_attempts_.push_back(attempt); |
| 108 | } |
| 109 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 110 | WebSocketHandshakeStreamBase::CreateHelper* |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 111 | HttpStreamRequest::websocket_handshake_stream_create_helper() const { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 112 | return websocket_handshake_stream_create_helper_; |
| 113 | } |
| 114 | |
[email protected] | 7f28a8df | 2011-02-25 22:26:03 | [diff] [blame] | 115 | } // namespace net |