From f030f4b139e4a0b5035a1647502414dcdd9016cf Mon Sep 17 00:00:00 2001 From: klzgrad Date: Thu, 17 Jan 2019 05:47:20 -0500 Subject: [PATCH] quic: Add support for HTTP/3 CONNECT Fast Open SpdyProxyClientSocket uses read_callback_ for both Connect() and Read(), and its OnIOComplete() calls read_callback_, thus its fast connect code checks read_callback_. The code was ported to QuicProxyClientSocket without much change. But QuicProxyClientSocket uses a separate connect_callback_ apart from read_callback_, and its OnIOComplete() calls connect_callback_, thus when headers are received after Connect() it doesn't need to check read_callback_ and should always avoid calling connect_callback_. --- src/net/quic/quic_proxy_client_socket.cc | 24 ++++++++++++++++++++++++ src/net/quic/quic_proxy_client_socket.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/net/quic/quic_proxy_client_socket.cc b/src/net/quic/quic_proxy_client_socket.cc index 925205b26f..4e3c6d4504 100644 --- a/src/net/quic/quic_proxy_client_socket.cc +++ b/src/net/quic/quic_proxy_client_socket.cc @@ -37,6 +37,10 @@ QuicProxyClientSocket::QuicProxyClientSocket( endpoint_(endpoint), auth_(auth_controller), user_agent_(user_agent), + // This is a hack to avoid messing up higer APIs. + // Should be false by default officially. + use_fastopen_(true), + read_headers_pending_(false), net_log_(net_log) { DCHECK(stream_->IsOpen()); @@ -312,6 +316,16 @@ int QuicProxyClientSocket::DoLoop(int last_io_result) { rv = DoReadReplyComplete(rv); net_log_.EndEventWithNetErrorCode( NetLogEventType::HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); + if (use_fastopen_ && read_headers_pending_) { + read_headers_pending_ = false; + if (rv < 0) { + // read_callback_ will be called with this error and be reset. + // Further data after that will be ignored. + next_state_ = STATE_DISCONNECTED; + } + // Prevents calling connect_callback_. + rv = ERR_IO_PENDING; + } break; default: NOTREACHED() << "bad state"; @@ -384,6 +398,11 @@ int QuicProxyClientSocket::DoReadReply() { &response_header_block_, base::BindOnce(&QuicProxyClientSocket::OnReadResponseHeadersComplete, weak_factory_.GetWeakPtr())); + if (use_fastopen_ && rv == ERR_IO_PENDING) { + read_headers_pending_ = true; + next_state_ = STATE_CONNECT_COMPLETE; + return OK; + } if (rv == ERR_IO_PENDING) return ERR_IO_PENDING; if (rv < 0) @@ -423,6 +442,11 @@ int QuicProxyClientSocket::DoReadReplyComplete(int result) { } void QuicProxyClientSocket::OnReadResponseHeadersComplete(int result) { + if (use_fastopen_ && read_headers_pending_ && + next_state_ == STATE_CONNECT_COMPLETE) { + next_state_ = STATE_READ_REPLY_COMPLETE; + } + // Convert the now-populated spdy::SpdyHeaderBlock to HttpResponseInfo if (result > 0) result = ProcessResponseHeaders(response_header_block_); diff --git a/src/net/quic/quic_proxy_client_socket.h b/src/net/quic/quic_proxy_client_socket.h index 299526c848..4d0cba95a5 100644 --- a/src/net/quic/quic_proxy_client_socket.h +++ b/src/net/quic/quic_proxy_client_socket.h @@ -142,6 +142,9 @@ class NET_EXPORT_PRIVATE QuicProxyClientSocket : public ProxyClientSocket { // Session connect timing info. LoadTimingInfo::ConnectTiming connect_timing_; + bool use_fastopen_; + bool read_headers_pending_; + const NetLogWithSource net_log_; // The default weak pointer factory.