Chromium Code Reviews| Index: net/quic/bidirectional_stream_quic_impl.cc |
| diff --git a/net/quic/bidirectional_stream_quic_impl.cc b/net/quic/bidirectional_stream_quic_impl.cc |
| index b85997b67f2cd479e66dcf7191657bfd439fea2c..3d1ae3cd4b31020e8638845d9e2ab2494acc7b27 100644 |
| --- a/net/quic/bidirectional_stream_quic_impl.cc |
| +++ b/net/quic/bidirectional_stream_quic_impl.cc |
| @@ -32,7 +32,7 @@ BidirectionalStreamQuicImpl::BidirectionalStreamQuicImpl( |
| closed_stream_sent_bytes_(0), |
| has_sent_headers_(false), |
| has_received_headers_(false), |
| - disable_auto_flush_(false), |
| + send_request_headers_automatically_(true), |
| weak_factory_(this) { |
| DCHECK(session_); |
| session_->AddObserver(this); |
| @@ -47,12 +47,12 @@ BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { |
| void BidirectionalStreamQuicImpl::Start( |
| const BidirectionalStreamRequestInfo* request_info, |
| const BoundNetLog& net_log, |
| - bool disable_auto_flush, |
| + bool send_request_headers_automatically, |
| BidirectionalStreamImpl::Delegate* delegate, |
| std::unique_ptr<base::Timer> /* timer */) { |
| DCHECK(!stream_); |
| - disable_auto_flush_ = disable_auto_flush; |
| + send_request_headers_automatically_ = send_request_headers_automatically; |
| if (!session_) { |
| NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR |
| : ERR_QUIC_HANDSHAKE_FAILED); |
| @@ -73,6 +73,25 @@ void BidirectionalStreamQuicImpl::Start( |
| } |
| } |
| +void BidirectionalStreamQuicImpl::SendRequestHeaders() { |
| + DCHECK(!has_sent_headers_); |
| + DCHECK(stream_); |
| + |
| + SpdyHeaderBlock headers; |
| + HttpRequestInfo http_request_info; |
| + http_request_info.url = request_info_->url; |
| + http_request_info.method = request_info_->method; |
|
mef
2016/06/01 21:33:21
Not for this CL, but we may consider making Bidire
xunjieli
2016/06/01 22:27:17
Acknowledged.
|
| + http_request_info.extra_headers = request_info_->extra_headers; |
| + |
| + CreateSpdyHeadersFromHttpRequest(http_request_info, |
| + http_request_info.extra_headers, HTTP2, true, |
| + &headers); |
| + size_t frame_len = stream_->WriteHeaders( |
|
mef
2016/06/01 21:33:21
nit: size_t frame_len => headers_bytes_sent_
xunjieli
2016/06/01 22:27:17
Done.
|
| + headers, request_info_->end_stream_on_headers, nullptr); |
| + headers_bytes_sent_ += frame_len; |
| + has_sent_headers_ = true; |
| +} |
| + |
| int BidirectionalStreamQuicImpl::ReadData(IOBuffer* buffer, int buffer_len) { |
| DCHECK(buffer); |
| DCHECK(buffer_len); |
| @@ -103,6 +122,16 @@ void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data, |
| DCHECK(stream_); |
| DCHECK(length > 0 || (length == 0 && end_stream)); |
| + std::unique_ptr<QuicConnection::ScopedPacketBundler> bundler; |
| + if (!has_sent_headers_) { |
| + DCHECK(!send_request_headers_automatically_); |
| + // Creates a bundler only if there are headers to be sent along with the |
| + // single data buffer. |
| + bundler.reset(new QuicConnection::ScopedPacketBundler( |
| + session_->connection(), QuicConnection::SEND_ACK_IF_PENDING)); |
| + SendRequestHeaders(); |
| + } |
| + |
| base::StringPiece string_data(data->data(), length); |
| int rv = stream_->WriteStreamData( |
| string_data, end_stream, |
| @@ -126,6 +155,7 @@ void BidirectionalStreamQuicImpl::SendvData( |
| QuicConnection::ScopedPacketBundler bundler( |
| session_->connection(), QuicConnection::SEND_ACK_IF_PENDING); |
| if (!has_sent_headers_) { |
| + DCHECK(!send_request_headers_automatically_); |
| SendRequestHeaders(); |
| } |
| @@ -238,10 +268,10 @@ void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { |
| DCHECK(rv == OK || !stream_); |
| if (rv == OK) { |
| stream_->SetDelegate(this); |
| - if (!disable_auto_flush_) { |
| + if (send_request_headers_automatically_) { |
| SendRequestHeaders(); |
| } |
| - delegate_->OnStreamReady(); |
| + delegate_->OnStreamReady(send_request_headers_automatically_); |
|
mef
2016/06/01 21:33:21
send_request_headers_automatically_ => has_sent_he
xunjieli
2016/06/01 22:27:16
Done.
|
| } else { |
| NotifyError(rv); |
| } |
| @@ -256,25 +286,6 @@ void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { |
| } |
| } |
| -void BidirectionalStreamQuicImpl::SendRequestHeaders() { |
| - DCHECK(!has_sent_headers_); |
| - DCHECK(stream_); |
| - |
| - SpdyHeaderBlock headers; |
| - 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; |
| - |
| - CreateSpdyHeadersFromHttpRequest(http_request_info, |
| - http_request_info.extra_headers, HTTP2, true, |
| - &headers); |
| - size_t frame_len = stream_->WriteHeaders( |
| - headers, request_info_->end_stream_on_headers, nullptr); |
| - headers_bytes_sent_ += frame_len; |
| - has_sent_headers_ = true; |
| -} |
| - |
| void BidirectionalStreamQuicImpl::NotifyError(int error) { |
| DCHECK_NE(OK, error); |
| DCHECK_NE(ERR_IO_PENDING, error); |