1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
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/callback.h"
10 #include "base/check.h"
11 #include "base/stl_util.h"
12 #include "net/http/bidirectional_stream_impl.h"
13 #include "net/log/net_log_event_type.h"
14 #include "net/spdy/bidirectional_stream_spdy_impl.h"
15 #include "net/spdy/spdy_http_stream.h"
16 #include "net/spdy/spdy_session.h"
17
18 namespace net {
19
HttpStreamRequest(const GURL & url,Helper * helper,HttpStreamRequest::Delegate * delegate,WebSocketHandshakeStreamBase::CreateHelper * websocket_handshake_stream_create_helper,const NetLogWithSource & net_log,StreamType stream_type)20 HttpStreamRequest::HttpStreamRequest(
21 const GURL& url,
22 Helper* helper,
23 HttpStreamRequest::Delegate* delegate,
24 WebSocketHandshakeStreamBase::CreateHelper*
25 websocket_handshake_stream_create_helper,
26 const NetLogWithSource& net_log,
27 StreamType stream_type)
28 : url_(url),
29 helper_(helper),
30 websocket_handshake_stream_create_helper_(
31 websocket_handshake_stream_create_helper),
32 net_log_(net_log),
33 completed_(false),
34 was_alpn_negotiated_(false),
35 negotiated_protocol_(kProtoUnknown),
36 using_spdy_(false),
37 stream_type_(stream_type) {
38 net_log_.BeginEvent(NetLogEventType::HTTP_STREAM_REQUEST);
39 }
40
~HttpStreamRequest()41 HttpStreamRequest::~HttpStreamRequest() {
42 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_REQUEST);
43 helper_->OnRequestComplete();
44 }
45
Complete(bool was_alpn_negotiated,NextProto negotiated_protocol,bool using_spdy)46 void HttpStreamRequest::Complete(bool was_alpn_negotiated,
47 NextProto negotiated_protocol,
48 bool using_spdy) {
49 DCHECK(!completed_);
50 completed_ = true;
51 was_alpn_negotiated_ = was_alpn_negotiated;
52 negotiated_protocol_ = negotiated_protocol;
53 using_spdy_ = using_spdy;
54 }
55
RestartTunnelWithProxyAuth()56 int HttpStreamRequest::RestartTunnelWithProxyAuth() {
57 return helper_->RestartTunnelWithProxyAuth();
58 }
59
SetPriority(RequestPriority priority)60 void HttpStreamRequest::SetPriority(RequestPriority priority) {
61 helper_->SetPriority(priority);
62 }
63
GetLoadState() const64 LoadState HttpStreamRequest::GetLoadState() const {
65 return helper_->GetLoadState();
66 }
67
was_alpn_negotiated() const68 bool HttpStreamRequest::was_alpn_negotiated() const {
69 DCHECK(completed_);
70 return was_alpn_negotiated_;
71 }
72
negotiated_protocol() const73 NextProto HttpStreamRequest::negotiated_protocol() const {
74 DCHECK(completed_);
75 return negotiated_protocol_;
76 }
77
using_spdy() const78 bool HttpStreamRequest::using_spdy() const {
79 DCHECK(completed_);
80 return using_spdy_;
81 }
82
connection_attempts() const83 const ConnectionAttempts& HttpStreamRequest::connection_attempts() const {
84 return connection_attempts_;
85 }
86
AddConnectionAttempts(const ConnectionAttempts & attempts)87 void HttpStreamRequest::AddConnectionAttempts(
88 const ConnectionAttempts& attempts) {
89 for (const auto& attempt : attempts)
90 connection_attempts_.push_back(attempt);
91 }
92
93 WebSocketHandshakeStreamBase::CreateHelper*
websocket_handshake_stream_create_helper() const94 HttpStreamRequest::websocket_handshake_stream_create_helper() const {
95 return websocket_handshake_stream_create_helper_;
96 }
97
98 } // namespace net
99