• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(bool was_alpn_negotiated,NextProto negotiated_protocol,AlternateProtocolUsage alternate_protocol_usage,bool using_spdy)41 void HttpStreamRequest::Complete(
42     bool was_alpn_negotiated,
43     NextProto negotiated_protocol,
44     AlternateProtocolUsage alternate_protocol_usage,
45     bool using_spdy) {
46   DCHECK(!completed_);
47   completed_ = true;
48   was_alpn_negotiated_ = was_alpn_negotiated;
49   negotiated_protocol_ = negotiated_protocol;
50   alternate_protocol_usage_ = alternate_protocol_usage;
51   using_spdy_ = using_spdy;
52 }
53 
RestartTunnelWithProxyAuth()54 int HttpStreamRequest::RestartTunnelWithProxyAuth() {
55   return helper_->RestartTunnelWithProxyAuth();
56 }
57 
SetPriority(RequestPriority priority)58 void HttpStreamRequest::SetPriority(RequestPriority priority) {
59   helper_->SetPriority(priority);
60 }
61 
GetLoadState() const62 LoadState HttpStreamRequest::GetLoadState() const {
63   return helper_->GetLoadState();
64 }
65 
was_alpn_negotiated() const66 bool HttpStreamRequest::was_alpn_negotiated() const {
67   DCHECK(completed_);
68   return was_alpn_negotiated_;
69 }
70 
negotiated_protocol() const71 NextProto HttpStreamRequest::negotiated_protocol() const {
72   DCHECK(completed_);
73   return negotiated_protocol_;
74 }
75 
alternate_protocol_usage() const76 AlternateProtocolUsage HttpStreamRequest::alternate_protocol_usage() const {
77   DCHECK(completed_);
78   return alternate_protocol_usage_;
79 }
80 
using_spdy() const81 bool HttpStreamRequest::using_spdy() const {
82   DCHECK(completed_);
83   return using_spdy_;
84 }
85 
connection_attempts() const86 const ConnectionAttempts& HttpStreamRequest::connection_attempts() const {
87   return connection_attempts_;
88 }
89 
AddConnectionAttempts(const ConnectionAttempts & attempts)90 void HttpStreamRequest::AddConnectionAttempts(
91     const ConnectionAttempts& attempts) {
92   for (const auto& attempt : attempts)
93     connection_attempts_.push_back(attempt);
94 }
95 
96 WebSocketHandshakeStreamBase::CreateHelper*
websocket_handshake_stream_create_helper() const97 HttpStreamRequest::websocket_handshake_stream_create_helper() const {
98   return websocket_handshake_stream_create_helper_;
99 }
100 
101 }  // namespace net
102