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(Helper * helper,HttpStreamRequest::Delegate * delegate,WebSocketHandshakeStreamBase::CreateHelper * websocket_handshake_stream_create_helper,const NetLogWithSource & net_log,StreamType stream_type)19 HttpStreamRequest::HttpStreamRequest(
20 Helper* helper,
21 HttpStreamRequest::Delegate* delegate,
22 WebSocketHandshakeStreamBase::CreateHelper*
23 websocket_handshake_stream_create_helper,
24 const NetLogWithSource& net_log,
25 StreamType stream_type)
26 : helper_(helper),
27 websocket_handshake_stream_create_helper_(
28 websocket_handshake_stream_create_helper),
29 net_log_(net_log),
30 stream_type_(stream_type) {
31 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_REQUEST);
32 }
33
~HttpStreamRequest()34 HttpStreamRequest::~HttpStreamRequest() {
35 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_REQUEST);
36 helper_.ExtractAsDangling()->OnRequestComplete(); // May delete `*helper_`;
37 }
38
Complete(NextProto negotiated_protocol,AlternateProtocolUsage alternate_protocol_usage)39 void HttpStreamRequest::Complete(
40 NextProto negotiated_protocol,
41 AlternateProtocolUsage alternate_protocol_usage) {
42 DCHECK(!completed_);
43 completed_ = true;
44 negotiated_protocol_ = negotiated_protocol;
45 alternate_protocol_usage_ = alternate_protocol_usage;
46 }
47
RestartTunnelWithProxyAuth()48 int HttpStreamRequest::RestartTunnelWithProxyAuth() {
49 return helper_->RestartTunnelWithProxyAuth();
50 }
51
SetPriority(RequestPriority priority)52 void HttpStreamRequest::SetPriority(RequestPriority priority) {
53 helper_->SetPriority(priority);
54 }
55
GetLoadState() const56 LoadState HttpStreamRequest::GetLoadState() const {
57 return helper_->GetLoadState();
58 }
59
negotiated_protocol() const60 NextProto HttpStreamRequest::negotiated_protocol() const {
61 DCHECK(completed_);
62 return negotiated_protocol_;
63 }
64
alternate_protocol_usage() const65 AlternateProtocolUsage HttpStreamRequest::alternate_protocol_usage() const {
66 DCHECK(completed_);
67 return alternate_protocol_usage_;
68 }
69
connection_attempts() const70 const ConnectionAttempts& HttpStreamRequest::connection_attempts() const {
71 return connection_attempts_;
72 }
73
AddConnectionAttempts(const ConnectionAttempts & attempts)74 void HttpStreamRequest::AddConnectionAttempts(
75 const ConnectionAttempts& attempts) {
76 for (const auto& attempt : attempts)
77 connection_attempts_.push_back(attempt);
78 }
79
80 WebSocketHandshakeStreamBase::CreateHelper*
websocket_handshake_stream_create_helper() const81 HttpStreamRequest::websocket_handshake_stream_create_helper() const {
82 return websocket_handshake_stream_create_helper_;
83 }
84
85 } // namespace net
86