OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/bidirectional_stream.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/thread_task_runner_handle.h" | |
10 #include "net/base/load_flags.h" | |
11 #include "net/base/net_errors.h" | |
12 #include "net/http/http_network_session.h" | |
13 #include "net/http/http_stream.h" | |
14 #include "net/log/net_log.h" | |
15 #include "net/ssl/ssl_cert_request_info.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace net { | |
19 | |
20 BidirectionalStream::RequestInfo::RequestInfo() {} | |
21 | |
22 BidirectionalStream::RequestInfo::~RequestInfo() {} | |
23 | |
24 BidirectionalStream::BidirectionalStream(const RequestInfo& request_info, | |
25 RequestPriority priority, | |
26 HttpNetworkSession* session, | |
27 Delegate* delegate) | |
28 : request_info_(request_info), | |
29 priority_(priority), | |
30 net_log_(BoundNetLog::Make(session->net_log(), | |
31 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), | |
32 delegate_(delegate) { | |
33 SSLConfig server_ssl_config; | |
34 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | |
35 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | |
36 session->GetNpnProtos(&server_ssl_config.npn_protos); | |
mmenke
2015/12/08 22:58:34
Hrm...This seems weird - the ssl_config_service on
xunjieli
2015/12/10 23:25:50
Yea. I had to find out about this in the hard way.
| |
37 | |
38 if (!request_info.url.SchemeIs("https")) { | |
39 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
40 FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_), | |
mmenke
2015/12/08 22:58:34
include base/bind, base/location.
xunjieli
2015/12/10 23:25:50
Done.
| |
41 ERR_DISALLOWED_URL_SCHEME)); | |
42 return; | |
43 } | |
44 | |
45 HttpRequestInfo http_request_info; | |
46 http_request_info.url = request_info.url; | |
47 http_request_info.method = request_info.method; | |
48 http_request_info.extra_headers = request_info.extra_headers; | |
49 stream_request_.reset( | |
50 session->http_stream_factory()->RequestBidirectionalStreamJob( | |
51 http_request_info, priority_, server_ssl_config, server_ssl_config, | |
52 this, net_log_)); | |
mmenke
2015/12/08 22:58:34
Should double-check this can't fail and invoke the
xunjieli
2015/12/10 23:25:50
How do we invoke the callback synchronously? Shoul
mmenke
2015/12/11 16:42:53
Sorry, I mean should double check that no HttpStre
xunjieli
2015/12/11 23:48:39
Done.
| |
53 } | |
54 | |
55 BidirectionalStream::~BidirectionalStream() { | |
56 Cancel(); | |
57 } | |
58 | |
59 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { | |
60 DCHECK(stream_job_); | |
61 | |
62 return stream_job_->ReadData(buf, buf_len); | |
63 } | |
64 | |
65 void BidirectionalStream::SendData(IOBuffer* data, | |
66 int length, | |
67 bool end_stream) { | |
68 DCHECK(stream_job_); | |
69 | |
70 stream_job_->SendData(data, length, end_stream); | |
71 } | |
72 | |
73 void BidirectionalStream::Cancel() { | |
74 if (stream_request_) | |
75 stream_request_.reset(); | |
76 if (stream_job_) | |
77 stream_job_->Cancel(); | |
78 } | |
79 | |
80 NextProto BidirectionalStream::GetProtocol() const { | |
81 DCHECK(stream_job_); | |
82 | |
83 return stream_job_->GetProtocol(); | |
84 } | |
85 | |
86 int64_t BidirectionalStream::GetTotalReceivedBytes() const { | |
87 DCHECK(stream_job_); | |
88 | |
89 return stream_job_->GetTotalReceivedBytes(); | |
90 } | |
91 | |
92 int64_t BidirectionalStream::GetTotalSentBytes() const { | |
93 DCHECK(stream_job_); | |
94 | |
95 return stream_job_->GetTotalSentBytes(); | |
96 } | |
97 | |
98 void BidirectionalStream::OnRequestHeadersSent() { | |
99 DCHECK(delegate_); | |
mmenke
2015/12/08 22:58:34
Get rid of this, and move it into the constructor?
xunjieli
2015/12/10 23:25:50
Done. Good idea!
| |
100 | |
101 delegate_->OnRequestHeadersSent(); | |
102 } | |
103 | |
104 void BidirectionalStream::OnHeaders(const SpdyHeaderBlock& response_headers) { | |
105 DCHECK(delegate_); | |
106 | |
107 delegate_->OnHeaders(response_headers); | |
108 } | |
109 | |
110 void BidirectionalStream::OnReadCompleted(int bytes_read) { | |
111 DCHECK(delegate_); | |
112 | |
113 delegate_->OnReadCompleted(bytes_read); | |
114 } | |
115 | |
116 void BidirectionalStream::OnDataSent() { | |
117 DCHECK(delegate_); | |
118 | |
119 delegate_->OnDataSent(); | |
120 } | |
121 | |
122 void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) { | |
123 DCHECK(delegate_); | |
124 | |
125 delegate_->OnTrailers(trailers); | |
126 } | |
127 | |
128 void BidirectionalStream::OnFailed(int status) { | |
129 DCHECK(delegate_); | |
130 | |
131 delegate_->OnFailed(status); | |
132 } | |
133 | |
134 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, | |
135 const ProxyInfo& used_proxy_info, | |
136 HttpStream* stream) { | |
137 NOTREACHED(); | |
138 } | |
139 | |
140 void BidirectionalStream::OnBidirectionalStreamJobReady( | |
141 const SSLConfig& used_ssl_config, | |
142 const ProxyInfo& used_proxy_info, | |
143 BidirectionalStreamJob* stream) { | |
144 DCHECK(!stream_job_); | |
145 | |
146 stream_job_.reset(stream); | |
147 stream_request_.reset(); | |
148 HttpRequestInfo http_request_info; | |
149 http_request_info.url = request_info_.url; | |
150 http_request_info.method = request_info_.method; | |
151 http_request_info.extra_headers = request_info_.extra_headers; | |
152 | |
153 stream_job_->Start(http_request_info, priority_, net_log_, this); | |
154 } | |
155 | |
156 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | |
157 const SSLConfig& used_ssl_config, | |
158 const ProxyInfo& used_proxy_info, | |
159 WebSocketHandshakeStreamBase* stream) { | |
160 NOTREACHED(); | |
161 } | |
162 | |
163 void BidirectionalStream::OnStreamFailed(int result, | |
164 const SSLConfig& used_ssl_config, | |
165 SSLFailureState ssl_failure_state) { | |
166 DCHECK_LT(result, 0); | |
167 DCHECK_NE(result, ERR_IO_PENDING); | |
168 DCHECK(stream_request_); | |
169 | |
170 delegate_->OnFailed(static_cast<Error>(result)); | |
171 } | |
172 | |
173 void BidirectionalStream::OnCertificateError(int result, | |
174 const SSLConfig& used_ssl_config, | |
175 const SSLInfo& ssl_info) { | |
176 DCHECK_LT(result, 0); | |
177 DCHECK_NE(result, ERR_IO_PENDING); | |
178 DCHECK(stream_request_); | |
179 | |
180 delegate_->OnFailed(static_cast<Error>(result)); | |
181 } | |
182 | |
183 void BidirectionalStream::OnNeedsProxyAuth( | |
184 const HttpResponseInfo& proxy_response, | |
185 const SSLConfig& used_ssl_config, | |
186 const ProxyInfo& used_proxy_info, | |
187 HttpAuthController* auth_controller) { | |
188 DCHECK(stream_request_); | |
189 | |
190 delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); | |
191 } | |
192 | |
193 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
194 SSLCertRequestInfo* cert_info) { | |
195 DCHECK(stream_request_); | |
196 | |
197 delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
198 } | |
199 | |
200 void BidirectionalStream::OnHttpsProxyTunnelResponse( | |
201 const HttpResponseInfo& response_info, | |
202 const SSLConfig& used_ssl_config, | |
203 const ProxyInfo& used_proxy_info, | |
204 HttpStream* stream) { | |
205 NOTREACHED(); | |
206 } | |
207 | |
208 } // namespace net | |
OLD | NEW |