diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc index 8631afddbf..0d389527c8 100644 --- a/net/spdy/spdy_proxy_client_socket.cc +++ b/net/spdy/spdy_proxy_client_socket.cc @@ -46,6 +46,10 @@ SpdyProxyClientSocket::SpdyProxyClientSocket( write_buffer_len_(0), was_ever_used_(false), redirect_has_load_timing_info_(false), + // This is a hack to avoid messing up higher APIs. + // Should be false by default officially. + use_fastopen_(true), + read_headers_pending_(false), net_log_(NetLogWithSource::Make(spdy_stream->net_log().net_log(), NetLogSourceType::PROXY_CLIENT_SOCKET)), source_dependency_(source_net_log.source()), @@ -322,6 +326,20 @@ int SpdyProxyClientSocket::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_ 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"; @@ -378,6 +396,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; @@ -441,6 +465,10 @@ void SpdyProxyClientSocket::OnHeadersSent() { void SpdyProxyClientSocket::OnHeadersReceived( const spdy::SpdyHeaderBlock& response_headers, const spdy::SpdyHeaderBlock* pushed_request_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/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h index 6aef81f458..615e82c7b8 100644 --- a/net/spdy/spdy_proxy_client_socket.h +++ b/net/spdy/spdy_proxy_client_socket.h @@ -176,6 +176,9 @@ class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket, bool redirect_has_load_timing_info_; LoadTimingInfo redirect_load_timing_info_; + bool use_fastopen_; + bool read_headers_pending_; + const NetLogWithSource net_log_; const NetLogSource source_dependency_;