1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http/http_stream_request.h"
6
7 #include <utility>
8
9 #include "base/check.h"
10 #include "base/functional/callback.h"
11 #include "net/http/bidirectional_stream_impl.h"
12 #include "net/log/net_log_event_type.h"
13 #include "net/spdy/bidirectional_stream_spdy_impl.h"
14 #include "net/spdy/spdy_http_stream.h"
15 #include "net/spdy/spdy_session.h"
16
17 namespace net {
18
HttpStreamRequest(const GURL & url,Helper * helper,HttpStreamRequest::Delegate * delegate,WebSocketHandshakeStreamBase::CreateHelper * websocket_handshake_stream_create_helper,const NetLogWithSource & net_log,StreamType stream_type)19 HttpStreamRequest::HttpStreamRequest(
20 const GURL& url,
21 Helper* helper,
22 HttpStreamRequest::Delegate* delegate,
23 WebSocketHandshakeStreamBase::CreateHelper*
24 websocket_handshake_stream_create_helper,
25 const NetLogWithSource& net_log,
26 StreamType stream_type)
27 : url_(url),
28 helper_(helper),
29 websocket_handshake_stream_create_helper_(
30 websocket_handshake_stream_create_helper),
31 net_log_(net_log),
32 stream_type_(stream_type) {
33 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_REQUEST);
34 }
35
~HttpStreamRequest()36 HttpStreamRequest::~HttpStreamRequest() {
37 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_REQUEST);
38 helper_.ExtractAsDangling()->OnRequestComplete(); // May delete `*helper_`;
39 }
40
Complete(NextProto negotiated_protocol,AlternateProtocolUsage alternate_protocol_usage)41 void HttpStreamRequest::Complete(
42 NextProto negotiated_protocol,
43 AlternateProtocolUsage alternate_protocol_usage) {
44 DCHECK(!completed_);
45 completed_ = true;
46 negotiated_protocol_ = negotiated_protocol;
47 alternate_protocol_usage_ = alternate_protocol_usage;
48 }
49
RestartTunnelWithProxyAuth()50 int HttpStreamRequest::RestartTunnelWithProxyAuth() {
51 return helper_->RestartTunnelWithProxyAuth();
52 }
53
SetPriority(RequestPriority priority)54 void HttpStreamRequest::SetPriority(RequestPriority priority) {
55 helper_->SetPriority(priority);
56 }
57
GetLoadState() const58 LoadState HttpStreamRequest::GetLoadState() const {
59 return helper_->GetLoadState();
60 }
61
negotiated_protocol() const62 NextProto HttpStreamRequest::negotiated_protocol() const {
63 DCHECK(completed_);
64 return negotiated_protocol_;
65 }
66
alternate_protocol_usage() const67 AlternateProtocolUsage HttpStreamRequest::alternate_protocol_usage() const {
68 DCHECK(completed_);
69 return alternate_protocol_usage_;
70 }
71
connection_attempts() const72 const ConnectionAttempts& HttpStreamRequest::connection_attempts() const {
73 return connection_attempts_;
74 }
75
AddConnectionAttempts(const ConnectionAttempts & attempts)76 void HttpStreamRequest::AddConnectionAttempts(
77 const ConnectionAttempts& attempts) {
78 for (const auto& attempt : attempts)
79 connection_attempts_.push_back(attempt);
80 }
81
82 WebSocketHandshakeStreamBase::CreateHelper*
websocket_handshake_stream_create_helper() const83 HttpStreamRequest::websocket_handshake_stream_create_helper() const {
84 return websocket_handshake_stream_create_helper_;
85 }
86
87 } // namespace net
88