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