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); | |
37 | |
38 if (!request_info.url.SchemeIs("https")) { | |
39 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
40 FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_), | |
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_)); | |
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 void BidirectionalStream::OnRequestHeadersSent() { | |
81 DCHECK(delegate_); | |
82 | |
83 delegate_->OnRequestHeadersSent(); | |
84 } | |
85 | |
86 void BidirectionalStream::OnHeaders(const SpdyHeaderBlock& response_headers) { | |
87 DCHECK(delegate_); | |
88 | |
89 delegate_->OnHeaders(response_headers); | |
90 } | |
91 | |
92 void BidirectionalStream::OnReadCompleted(int bytes_read) { | |
93 DCHECK(delegate_); | |
94 | |
95 delegate_->OnReadCompleted(bytes_read); | |
96 } | |
97 | |
98 void BidirectionalStream::OnDataSent() { | |
99 DCHECK(delegate_); | |
100 | |
101 delegate_->OnDataSent(); | |
102 } | |
103 | |
104 void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) { | |
105 DCHECK(delegate_); | |
106 | |
107 delegate_->OnTrailers(trailers); | |
108 } | |
109 | |
110 void BidirectionalStream::OnFailed(int status) { | |
111 DCHECK(delegate_); | |
112 | |
113 delegate_->OnFailed(status); | |
114 } | |
115 | |
116 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, | |
117 const ProxyInfo& used_proxy_info, | |
118 HttpStream* stream) { | |
119 NOTREACHED(); | |
120 } | |
121 | |
122 void BidirectionalStream::OnBidirectionalStreamJobReady( | |
123 const SSLConfig& used_ssl_config, | |
124 const ProxyInfo& used_proxy_info, | |
125 BidirectionalStreamJob* stream) { | |
126 DCHECK(!stream_job_); | |
127 | |
128 stream_job_.reset(stream); | |
129 stream_request_.reset(); | |
130 HttpRequestInfo http_request_info; | |
131 http_request_info.url = request_info_.url; | |
132 http_request_info.method = request_info_.method; | |
133 http_request_info.extra_headers = request_info_.extra_headers; | |
134 | |
135 stream_job_->Start(http_request_info, priority_, net_log_, this); | |
136 } | |
137 | |
138 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | |
139 const SSLConfig& used_ssl_config, | |
140 const ProxyInfo& used_proxy_info, | |
141 WebSocketHandshakeStreamBase* stream) { | |
142 NOTREACHED(); | |
143 } | |
144 | |
145 void BidirectionalStream::OnStreamFailed(int result, | |
146 const SSLConfig& used_ssl_config, | |
147 SSLFailureState ssl_failure_state) { | |
148 DCHECK_LT(result, 0); | |
149 DCHECK_NE(result, ERR_IO_PENDING); | |
150 DCHECK(stream_request_); | |
151 | |
152 delegate_->OnFailed(static_cast<Error>(result)); | |
153 } | |
154 | |
155 void BidirectionalStream::OnCertificateError(int result, | |
156 const SSLConfig& used_ssl_config, | |
157 const SSLInfo& ssl_info) { | |
158 DCHECK_LT(result, 0); | |
159 DCHECK_NE(result, ERR_IO_PENDING); | |
160 DCHECK(stream_request_); | |
161 | |
162 delegate_->OnFailed(static_cast<Error>(result)); | |
163 } | |
164 | |
165 void BidirectionalStream::OnNeedsProxyAuth( | |
166 const HttpResponseInfo& proxy_response, | |
167 const SSLConfig& used_ssl_config, | |
168 const ProxyInfo& used_proxy_info, | |
169 HttpAuthController* auth_controller) { | |
170 DCHECK(stream_request_); | |
171 | |
172 delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); | |
173 } | |
174 | |
175 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
176 SSLCertRequestInfo* cert_info) { | |
177 DCHECK(stream_request_); | |
178 | |
179 delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
mef
2015/12/07 21:18:07
per crbug.com/558420 we should allow connection to
xunjieli
2015/12/08 16:08:46
Let's leave this for another time. If we want to d
| |
180 } | |
181 | |
182 void BidirectionalStream::OnHttpsProxyTunnelResponse( | |
183 const HttpResponseInfo& response_info, | |
184 const SSLConfig& used_ssl_config, | |
185 const ProxyInfo& used_proxy_info, | |
186 HttpStream* stream) { | |
187 NOTREACHED(); | |
188 } | |
189 | |
190 } // namespace net | |
OLD | NEW |