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_request_info.h" |
| 14 #include "net/http/http_stream.h" |
| 15 #include "net/log/net_log.h" |
| 16 #include "net/ssl/ssl_cert_request_info.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace net { |
| 20 |
| 21 BidirectionalStream::BidirectionalStream(const HttpRequestInfo& request_info, |
| 22 RequestPriority priority, |
| 23 HttpNetworkSession* session, |
| 24 Delegate* delegate) |
| 25 : request_info_(request_info), |
| 26 priority_(priority), |
| 27 net_log_(BoundNetLog::Make(session->net_log(), |
| 28 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
| 29 delegate_(delegate) { |
| 30 DCHECK(!request_info.upload_data_stream); |
| 31 DCHECK_EQ(LOAD_NORMAL, request_info.load_flags); |
| 32 |
| 33 SSLConfig server_ssl_config; |
| 34 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
| 35 |
| 36 if (!request_info.url.SchemeIs("https")) { |
| 37 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 38 FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_), |
| 39 ERR_DISALLOWED_URL_SCHEME)); |
| 40 return; |
| 41 } |
| 42 |
| 43 stream_request_.reset( |
| 44 session->http_stream_factory()->RequestBidirectionalStreamJob( |
| 45 request_info_, priority_, server_ssl_config, server_ssl_config, this, |
| 46 net_log_)); |
| 47 } |
| 48 |
| 49 BidirectionalStream::~BidirectionalStream() {} |
| 50 |
| 51 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { |
| 52 DCHECK(stream_); |
| 53 |
| 54 return stream_->ReadData(buf, buf_len); |
| 55 } |
| 56 |
| 57 void BidirectionalStream::SendData(IOBuffer* data, |
| 58 int length, |
| 59 bool end_stream) { |
| 60 DCHECK(stream_); |
| 61 |
| 62 stream_->SendData(data, length, end_stream); |
| 63 } |
| 64 |
| 65 void BidirectionalStream::Cancel() { |
| 66 if (stream_request_) |
| 67 stream_request_.reset(); |
| 68 if (stream_) |
| 69 stream_->Cancel(); |
| 70 } |
| 71 |
| 72 void BidirectionalStream::OnFailed(Error error) { |
| 73 DCHECK(delegate_); |
| 74 |
| 75 delegate_->OnFailed(error); |
| 76 } |
| 77 |
| 78 void BidirectionalStream::OnRequestHeadersSent() { |
| 79 DCHECK(delegate_); |
| 80 |
| 81 delegate_->OnRequestHeadersSent(); |
| 82 } |
| 83 |
| 84 void BidirectionalStream::OnHeaders(const SpdyHeaderBlock& response_headers) { |
| 85 DCHECK(delegate_); |
| 86 |
| 87 delegate_->OnHeaders(response_headers); |
| 88 } |
| 89 |
| 90 void BidirectionalStream::OnReadCompleted(int bytes_read) { |
| 91 DCHECK(delegate_); |
| 92 |
| 93 delegate_->OnReadCompleted(bytes_read); |
| 94 } |
| 95 |
| 96 void BidirectionalStream::OnDataSent() { |
| 97 DCHECK(delegate_); |
| 98 |
| 99 delegate_->OnDataSent(); |
| 100 } |
| 101 |
| 102 void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) { |
| 103 DCHECK(delegate_); |
| 104 |
| 105 delegate_->OnTrailers(trailers); |
| 106 } |
| 107 |
| 108 void BidirectionalStream::OnClose(int status) { |
| 109 DCHECK(delegate_); |
| 110 |
| 111 delegate_->OnClose(status); |
| 112 } |
| 113 |
| 114 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, |
| 115 const ProxyInfo& used_proxy_info, |
| 116 HttpStream* stream) { |
| 117 NOTREACHED(); |
| 118 } |
| 119 |
| 120 void BidirectionalStream::OnBidirectionalStreamJobReady( |
| 121 const SSLConfig& used_ssl_config, |
| 122 const ProxyInfo& used_proxy_info, |
| 123 BidirectionalStreamJob* stream) { |
| 124 DCHECK(!stream_); |
| 125 |
| 126 stream_.reset(stream); |
| 127 stream_request_.reset(); |
| 128 stream_->Start(request_info_, priority_, net_log_, this); |
| 129 } |
| 130 |
| 131 void BidirectionalStream::OnWebSocketHandshakeStreamReady( |
| 132 const SSLConfig& used_ssl_config, |
| 133 const ProxyInfo& used_proxy_info, |
| 134 WebSocketHandshakeStreamBase* stream) { |
| 135 NOTREACHED(); |
| 136 } |
| 137 |
| 138 void BidirectionalStream::OnStreamFailed(int result, |
| 139 const SSLConfig& used_ssl_config, |
| 140 SSLFailureState ssl_failure_state) { |
| 141 DCHECK_LT(result, 0); |
| 142 DCHECK_NE(result, ERR_IO_PENDING); |
| 143 DCHECK(stream_request_); |
| 144 |
| 145 delegate_->OnFailed(static_cast<Error>(result)); |
| 146 } |
| 147 |
| 148 void BidirectionalStream::OnCertificateError(int result, |
| 149 const SSLConfig& used_ssl_config, |
| 150 const SSLInfo& ssl_info) { |
| 151 DCHECK_LT(result, 0); |
| 152 DCHECK_NE(result, ERR_IO_PENDING); |
| 153 DCHECK(stream_request_); |
| 154 |
| 155 delegate_->OnFailed(static_cast<Error>(result)); |
| 156 } |
| 157 |
| 158 void BidirectionalStream::OnNeedsProxyAuth( |
| 159 const HttpResponseInfo& proxy_response, |
| 160 const SSLConfig& used_ssl_config, |
| 161 const ProxyInfo& used_proxy_info, |
| 162 HttpAuthController* auth_controller) { |
| 163 DCHECK(stream_request_); |
| 164 |
| 165 delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); |
| 166 } |
| 167 |
| 168 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
| 169 SSLCertRequestInfo* cert_info) { |
| 170 DCHECK(stream_request_); |
| 171 |
| 172 delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 173 } |
| 174 |
| 175 void BidirectionalStream::OnHttpsProxyTunnelResponse( |
| 176 const HttpResponseInfo& response_info, |
| 177 const SSLConfig& used_ssl_config, |
| 178 const ProxyInfo& used_proxy_info, |
| 179 HttpStream* stream) { |
| 180 NOTREACHED(); |
| 181 } |
| 182 |
| 183 } // namespace net |
OLD | NEW |