blob: 1f223511c90072219374507c9fde5aca0e10e757 [file] [log] [blame]
[email protected]5477d892012-03-01 21:31:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7f28a8df2011-02-25 22:26:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Bence Béky6b44abf2018-04-11 10:32:515#include "net/http/http_stream_request.h"
[email protected]7f28a8df2011-02-25 22:26:036
Bence Béky6d05ebd2017-05-16 00:09:017#include <utility>
8
[email protected]b6754252012-06-13 23:14:389#include "base/callback.h"
[email protected]7f28a8df2011-02-25 22:26:0310#include "base/logging.h"
[email protected]7286e3fc2011-07-19 22:13:2411#include "base/stl_util.h"
xunjieli5749218c2016-03-22 16:43:0612#include "net/http/bidirectional_stream_impl.h"
mikecirone8b85c432016-09-08 19:11:0013#include "net/log/net_log_event_type.h"
Bence Béky94658bf2018-05-11 19:22:5814#include "net/spdy/spdy_http_stream.h"
15#include "net/spdy/spdy_session.h"
[email protected]7f28a8df2011-02-25 22:26:0316
17namespace net {
18
Bence Béky6b44abf2018-04-11 10:32:5119HttpStreamRequest::HttpStreamRequest(
[email protected]3732cea2013-06-21 06:50:5020 const GURL& url,
Helen Lif62edf732017-08-23 22:25:1821 Helper* helper,
[email protected]3732cea2013-06-21 06:50:5022 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4623 WebSocketHandshakeStreamBase::CreateHelper*
24 websocket_handshake_stream_create_helper,
tfarina428341112016-09-22 13:38:2025 const NetLogWithSource& net_log,
Helen Lif62edf732017-08-23 22:25:1826 StreamType stream_type)
[email protected]7f28a8df2011-02-25 22:26:0327 : url_(url),
Helen Lif62edf732017-08-23 22:25:1828 helper_(helper),
[email protected]467086b2013-11-12 08:19:4629 websocket_handshake_stream_create_helper_(
30 websocket_handshake_stream_create_helper),
[email protected]7b496b32011-02-28 22:25:5931 net_log_(net_log),
[email protected]7f28a8df2011-02-25 22:26:0332 completed_(false),
bnc94c92842016-09-21 15:22:5233 was_alpn_negotiated_(false),
bnc6227b26e2016-08-12 02:00:4334 negotiated_protocol_(kProtoUnknown),
xunjieli11834f02015-12-22 04:27:0835 using_spdy_(false),
Helen Lif62edf732017-08-23 22:25:1836 stream_type_(stream_type) {
mikecirone8b85c432016-09-08 19:11:0037 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_REQUEST);
[email protected]7f28a8df2011-02-25 22:26:0338}
39
Bence Béky6b44abf2018-04-11 10:32:5140HttpStreamRequest::~HttpStreamRequest() {
mikecirone8b85c432016-09-08 19:11:0041 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_REQUEST);
Helen Lif62edf732017-08-23 22:25:1842 helper_->OnRequestComplete();
[email protected]7f28a8df2011-02-25 22:26:0343}
44
Bence Béky6b44abf2018-04-11 10:32:5145void HttpStreamRequest::Complete(bool was_alpn_negotiated,
46 NextProto negotiated_protocol,
47 bool using_spdy) {
[email protected]7f28a8df2011-02-25 22:26:0348 DCHECK(!completed_);
49 completed_ = true;
bnc94c92842016-09-21 15:22:5250 was_alpn_negotiated_ = was_alpn_negotiated;
bnc6227b26e2016-08-12 02:00:4351 negotiated_protocol_ = negotiated_protocol;
[email protected]7f28a8df2011-02-25 22:26:0352 using_spdy_ = using_spdy;
[email protected]7f28a8df2011-02-25 22:26:0353}
54
Bence Béky6b44abf2018-04-11 10:32:5155void HttpStreamRequest::OnStreamReadyOnPooledConnection(
[email protected]7f28a8df2011-02-25 22:26:0356 const SSLConfig& used_ssl_config,
57 const ProxyInfo& used_proxy_info,
bnc5029f4632017-06-08 16:19:0058 std::unique_ptr<HttpStream> stream) {
[email protected]7f28a8df2011-02-25 22:26:0359 DCHECK(completed_);
Helen Lif62edf732017-08-23 22:25:1860 helper_->OnStreamReadyOnPooledConnection(used_ssl_config, used_proxy_info,
61 std::move(stream));
[email protected]7f28a8df2011-02-25 22:26:0362}
63
Bence Béky6b44abf2018-04-11 10:32:5164void HttpStreamRequest::OnBidirectionalStreamImplReadyOnPooledConnection(
65 const SSLConfig& used_ssl_config,
66 const ProxyInfo& used_proxy_info,
67 std::unique_ptr<BidirectionalStreamImpl> stream) {
xunjieli11834f02015-12-22 04:27:0868 DCHECK(completed_);
Helen Lif62edf732017-08-23 22:25:1869 helper_->OnBidirectionalStreamImplReadyOnPooledConnection(
Bence Békyfe7f0f482017-06-27 23:12:1070 used_ssl_config, used_proxy_info, std::move(stream));
[email protected]7f28a8df2011-02-25 22:26:0371}
72
Bence Béky6b44abf2018-04-11 10:32:5173int HttpStreamRequest::RestartTunnelWithProxyAuth() {
Helen Lif62edf732017-08-23 22:25:1874 return helper_->RestartTunnelWithProxyAuth();
[email protected]7f28a8df2011-02-25 22:26:0375}
76
Bence Béky6b44abf2018-04-11 10:32:5177void HttpStreamRequest::SetPriority(RequestPriority priority) {
Helen Lif62edf732017-08-23 22:25:1878 helper_->SetPriority(priority);
[email protected]bf828982013-08-14 18:01:4779}
80
Bence Béky6b44abf2018-04-11 10:32:5181LoadState HttpStreamRequest::GetLoadState() const {
Helen Lif62edf732017-08-23 22:25:1882 return helper_->GetLoadState();
[email protected]7f28a8df2011-02-25 22:26:0383}
84
Bence Béky6b44abf2018-04-11 10:32:5185bool HttpStreamRequest::was_alpn_negotiated() const {
[email protected]7f28a8df2011-02-25 22:26:0386 DCHECK(completed_);
bnc94c92842016-09-21 15:22:5287 return was_alpn_negotiated_;
[email protected]7f28a8df2011-02-25 22:26:0388}
89
Bence Béky6b44abf2018-04-11 10:32:5190NextProto HttpStreamRequest::negotiated_protocol() const {
[email protected]c30bcce2011-12-20 17:50:5191 DCHECK(completed_);
bnc6227b26e2016-08-12 02:00:4392 return negotiated_protocol_;
[email protected]c30bcce2011-12-20 17:50:5193}
94
Bence Béky6b44abf2018-04-11 10:32:5195bool HttpStreamRequest::using_spdy() const {
[email protected]7f28a8df2011-02-25 22:26:0396 DCHECK(completed_);
97 return using_spdy_;
98}
99
Bence Béky6b44abf2018-04-11 10:32:51100const ConnectionAttempts& HttpStreamRequest::connection_attempts() const {
ttuttle1f2d7e92015-04-28 16:17:47101 return connection_attempts_;
102}
103
Bence Béky6b44abf2018-04-11 10:32:51104void HttpStreamRequest::AddConnectionAttempts(
ttuttle1f2d7e92015-04-28 16:17:47105 const ConnectionAttempts& attempts) {
106 for (const auto& attempt : attempts)
107 connection_attempts_.push_back(attempt);
108}
109
Bence Béky2fcf4fa2018-04-06 20:06:01110WebSocketHandshakeStreamBase::CreateHelper*
Bence Béky6b44abf2018-04-11 10:32:51111HttpStreamRequest::websocket_handshake_stream_create_helper() const {
Bence Béky2fcf4fa2018-04-06 20:06:01112 return websocket_handshake_stream_create_helper_;
113}
114
[email protected]7f28a8df2011-02-25 22:26:03115} // namespace net