| 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..6cd932ff9854a6aa3fc6d0b33f2f9062d386dfbc
|
| --- /dev/null
|
| +++ b/net/http/bidirectional_stream.cc
|
| @@ -0,0 +1,190 @@
|
| +// 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_stream.h"
|
| +#include "net/log/net_log.h"
|
| +#include "net/ssl/ssl_cert_request_info.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace net {
|
| +
|
| +BidirectionalStream::RequestInfo::RequestInfo() {}
|
| +
|
| +BidirectionalStream::RequestInfo::~RequestInfo() {}
|
| +
|
| +BidirectionalStream::BidirectionalStream(const RequestInfo& 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) {
|
| + SSLConfig server_ssl_config;
|
| + session->ssl_config_service()->GetSSLConfig(&server_ssl_config);
|
| + session->GetAlpnProtos(&server_ssl_config.alpn_protos);
|
| + session->GetNpnProtos(&server_ssl_config.npn_protos);
|
| +
|
| + if (!request_info.url.SchemeIs("https")) {
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_),
|
| + ERR_DISALLOWED_URL_SCHEME));
|
| + return;
|
| + }
|
| +
|
| + HttpRequestInfo http_request_info;
|
| + http_request_info.url = request_info.url;
|
| + http_request_info.method = request_info.method;
|
| + http_request_info.extra_headers = request_info.extra_headers;
|
| + stream_request_.reset(
|
| + session->http_stream_factory()->RequestBidirectionalStreamJob(
|
| + http_request_info, priority_, server_ssl_config, server_ssl_config,
|
| + this, net_log_));
|
| +}
|
| +
|
| +BidirectionalStream::~BidirectionalStream() {
|
| + Cancel();
|
| +}
|
| +
|
| +int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
|
| + DCHECK(stream_job_);
|
| +
|
| + return stream_job_->ReadData(buf, buf_len);
|
| +}
|
| +
|
| +void BidirectionalStream::SendData(IOBuffer* data,
|
| + int length,
|
| + bool end_stream) {
|
| + DCHECK(stream_job_);
|
| +
|
| + stream_job_->SendData(data, length, end_stream);
|
| +}
|
| +
|
| +void BidirectionalStream::Cancel() {
|
| + if (stream_request_)
|
| + stream_request_.reset();
|
| + if (stream_job_)
|
| + stream_job_->Cancel();
|
| +}
|
| +
|
| +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::OnFailed(int status) {
|
| + DCHECK(delegate_);
|
| +
|
| + delegate_->OnFailed(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_job_);
|
| +
|
| + stream_job_.reset(stream);
|
| + stream_request_.reset();
|
| + HttpRequestInfo http_request_info;
|
| + http_request_info.url = request_info_.url;
|
| + http_request_info.method = request_info_.method;
|
| + http_request_info.extra_headers = request_info_.extra_headers;
|
| +
|
| + stream_job_->Start(http_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
|
|
|