diff --git a/src/net/spdy/spdy_proxy_client_socket.cc b/src/net/spdy/spdy_proxy_client_socket.cc index 9ac5064025..804ef7ba72 100644 --- a/src/net/spdy/spdy_proxy_client_socket.cc +++ b/src/net/spdy/spdy_proxy_client_socket.cc @@ -373,6 +373,20 @@ int SpdyProxyClientSocket::DoLoop(int last_io_result) { case STATE_PROCESS_RESPONSE_CODE: DCHECK_EQ(OK, rv); rv = DoProcessResponseCode(); + if (use_fastopen_ && read_headers_pending_) { + read_headers_pending_ = false; + if (rv < 0) { + // read_callback_ cannot be called. + if (!read_callback_) + rv = ERR_IO_PENDING; + // read_callback_ will be called with this error and be reset. + // Further data after that will be ignored. + next_state_ = STATE_DISCONNECTED; + } else { + // Does not call read_callback_ from here if headers are OK. + rv = ERR_IO_PENDING; + } + } break; default: NOTREACHED() << "bad state"; @@ -434,6 +448,10 @@ int SpdyProxyClientSocket::DoCalculateHeadersComplete(int result) { return result; } next_state_ = STATE_SEND_REQUEST; + if (proxy_delegate_headers_.HasHeader("fastopen")) { + proxy_delegate_headers_.RemoveHeader("fastopen"); + use_fastopen_ = true; + } request_.extra_headers.MergeFrom(proxy_delegate_headers_); return result; } @@ -461,6 +479,12 @@ int SpdyProxyClientSocket::DoSendRequestComplete(int result) { if (result < 0) return result; + if (use_fastopen_) { + read_headers_pending_ = true; + next_state_ = STATE_OPEN; + return OK; + } + // Wait for HEADERS frame from the server next_state_ = STATE_READ_REPLY_COMPLETE; return ERR_IO_PENDING; @@ -541,6 +565,10 @@ void SpdyProxyClientSocket::OnEarlyHintsReceived( void SpdyProxyClientSocket::OnHeadersReceived( const quiche::HttpHeaderBlock& response_headers) { + if (use_fastopen_ && read_headers_pending_ && next_state_ == STATE_OPEN) { + next_state_ = STATE_READ_REPLY_COMPLETE; + } + // If we've already received the reply, existing headers are too late. // TODO(mbelshe): figure out a way to make HEADERS frames useful after the // initial response. diff --git a/src/net/spdy/spdy_proxy_client_socket.h b/src/net/spdy/spdy_proxy_client_socket.h index e5e2353914..aca80e455b 100644 --- a/src/net/spdy/spdy_proxy_client_socket.h +++ b/src/net/spdy/spdy_proxy_client_socket.h @@ -200,6 +200,9 @@ class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket, // True if the transport socket has ever sent data. bool was_ever_used_ = false; + bool use_fastopen_ = false; + bool read_headers_pending_ = false; + const NetLogWithSource net_log_; const NetLogSource source_dependency_;