| Index: net/http/bidirectional_stream.cc
|
| diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e65dc0a03601c53dc542ed5625237b798230ae35
|
| --- /dev/null
|
| +++ b/net/http/bidirectional_stream.cc
|
| @@ -0,0 +1,183 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "net/http/bidirectional_stream.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +#include "net/base/load_flags.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "net/http/http_network_session.h"
|
| +#include "net/http/http_request_info.h"
|
| +#include "net/http/http_stream.h"
|
| +#include "net/log/net_log.h"
|
| +#include "net/ssl/ssl_cert_request_info.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace net {
|
| +
|
| +BidirectionalStream::BidirectionalStream(const HttpRequestInfo& request_info,
|
| + RequestPriority priority,
|
| + HttpNetworkSession* session,
|
| + Delegate* delegate)
|
| + : request_info_(request_info),
|
| + priority_(priority),
|
| + net_log_(BoundNetLog::Make(session->net_log(),
|
| + NetLog::SOURCE_BIDIRECTIONAL_STREAM)),
|
| + delegate_(delegate) {
|
| + DCHECK(!request_info.upload_data_stream);
|
| + DCHECK_EQ(LOAD_NORMAL, request_info.load_flags);
|
| +
|
| + SSLConfig server_ssl_config;
|
| + session->ssl_config_service()->GetSSLConfig(&server_ssl_config);
|
| +
|
| + if (!request_info.url.SchemeIs("https")) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_),
|
| + ERR_DISALLOWED_URL_SCHEME));
|
| + return;
|
| + }
|
| +
|
| + stream_request_.reset(
|
| + session->http_stream_factory()->RequestBidirectionalStreamJob(
|
| + request_info_, priority_, server_ssl_config, server_ssl_config, this,
|
| + net_log_));
|
| +}
|
| +
|
| +BidirectionalStream::~BidirectionalStream() {}
|
| +
|
| +int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
|
| + DCHECK(stream_);
|
| +
|
| + return stream_->ReadData(buf, buf_len);
|
| +}
|
| +
|
| +void BidirectionalStream::SendData(IOBuffer* data,
|
| + int length,
|
| + bool end_stream) {
|
| + DCHECK(stream_);
|
| +
|
| + stream_->SendData(data, length, end_stream);
|
| +}
|
| +
|
| +void BidirectionalStream::Cancel() {
|
| + if (stream_request_)
|
| + stream_request_.reset();
|
| + if (stream_)
|
| + stream_->Cancel();
|
| +}
|
| +
|
| +void BidirectionalStream::OnFailed(Error error) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnFailed(error);
|
| +}
|
| +
|
| +void BidirectionalStream::OnRequestHeadersSent() {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnRequestHeadersSent();
|
| +}
|
| +
|
| +void BidirectionalStream::OnHeaders(const SpdyHeaderBlock& response_headers) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnHeaders(response_headers);
|
| +}
|
| +
|
| +void BidirectionalStream::OnReadCompleted(int bytes_read) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnReadCompleted(bytes_read);
|
| +}
|
| +
|
| +void BidirectionalStream::OnDataSent() {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnDataSent();
|
| +}
|
| +
|
| +void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnTrailers(trailers);
|
| +}
|
| +
|
| +void BidirectionalStream::OnClose(int status) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnClose(status);
|
| +}
|
| +
|
| +void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + HttpStream* stream) {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +void BidirectionalStream::OnBidirectionalStreamJobReady(
|
| + const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + BidirectionalStreamJob* stream) {
|
| + DCHECK(!stream_);
|
| +
|
| + stream_.reset(stream);
|
| + stream_request_.reset();
|
| + stream_->Start(request_info_, priority_, net_log_, this);
|
| +}
|
| +
|
| +void BidirectionalStream::OnWebSocketHandshakeStreamReady(
|
| + const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + WebSocketHandshakeStreamBase* stream) {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +void BidirectionalStream::OnStreamFailed(int result,
|
| + const SSLConfig& used_ssl_config,
|
| + SSLFailureState ssl_failure_state) {
|
| + DCHECK_LT(result, 0);
|
| + DCHECK_NE(result, ERR_IO_PENDING);
|
| + DCHECK(stream_request_);
|
| +
|
| + delegate_->OnFailed(static_cast<Error>(result));
|
| +}
|
| +
|
| +void BidirectionalStream::OnCertificateError(int result,
|
| + const SSLConfig& used_ssl_config,
|
| + const SSLInfo& ssl_info) {
|
| + DCHECK_LT(result, 0);
|
| + DCHECK_NE(result, ERR_IO_PENDING);
|
| + DCHECK(stream_request_);
|
| +
|
| + delegate_->OnFailed(static_cast<Error>(result));
|
| +}
|
| +
|
| +void BidirectionalStream::OnNeedsProxyAuth(
|
| + const HttpResponseInfo& proxy_response,
|
| + const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + HttpAuthController* auth_controller) {
|
| + DCHECK(stream_request_);
|
| +
|
| + delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED);
|
| +}
|
| +
|
| +void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config,
|
| + SSLCertRequestInfo* cert_info) {
|
| + DCHECK(stream_request_);
|
| +
|
| + delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
|
| +}
|
| +
|
| +void BidirectionalStream::OnHttpsProxyTunnelResponse(
|
| + const HttpResponseInfo& response_info,
|
| + const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + HttpStream* stream) {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +} // namespace net
|
|
|