Chromium Code Reviews| Index: net/http/http_stream_parser.cc |
| diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc |
| index b673689ed296c510ab1a7d89f764c5424235e5c9..7ca21f5b05fa64f0dcd1dd3b0563c98e5e10ed6e 100644 |
| --- a/net/http/http_stream_parser.cc |
| +++ b/net/http/http_stream_parser.cc |
| @@ -333,6 +333,7 @@ int HttpStreamParser::ReadResponseHeaders(const CompletionCallback& callback) { |
| DCHECK(callback_.is_null()); |
| DCHECK(!callback.is_null()); |
| DCHECK_EQ(0, read_buf_unused_offset_); |
| + DCHECK(SendRequestBuffersEmpty()); |
| // This function can be called with io_state_ == STATE_DONE if the |
| // connection is closed after seeing just a 1xx response code. |
| @@ -369,6 +370,7 @@ int HttpStreamParser::ReadResponseBody(IOBuffer* buf, int buf_len, |
| DCHECK(callback_.is_null()); |
| DCHECK(!callback.is_null()); |
| DCHECK_LE(buf_len, kMaxBufSize); |
| + DCHECK(SendRequestBuffersEmpty()); |
| // Added to investigate crbug.com/499663. |
| CHECK(buf); |
| @@ -409,19 +411,27 @@ int HttpStreamParser::DoLoop(int result) { |
| case STATE_SEND_HEADERS: |
| DCHECK_EQ(OK, result); |
| result = DoSendHeaders(); |
| + DCHECK_NE(STATE_NONE, io_state_); |
| break; |
| case STATE_SEND_HEADERS_COMPLETE: |
| result = DoSendHeadersComplete(result); |
| + DCHECK_NE(STATE_NONE, io_state_); |
| break; |
| case STATE_SEND_BODY: |
| DCHECK_EQ(OK, result); |
| result = DoSendBody(); |
| + DCHECK_NE(STATE_NONE, io_state_); |
| break; |
| case STATE_SEND_BODY_COMPLETE: |
| result = DoSendBodyComplete(result); |
| + DCHECK_NE(STATE_NONE, io_state_); |
| break; |
| case STATE_SEND_REQUEST_READ_BODY_COMPLETE: |
| result = DoSendRequestReadBodyComplete(result); |
| + DCHECK_NE(STATE_NONE, io_state_); |
| + break; |
| + case STATE_SEND_REQUEST_COMPLETE: |
| + result = DoSendRequestComplete(result); |
| break; |
| case STATE_READ_HEADERS: |
| net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); |
| @@ -475,6 +485,7 @@ int HttpStreamParser::DoSendHeadersComplete(int result) { |
| // the headers were sent, but not all of the body way, and |result| is |
| // an error that this should try reading after, stash the error for now and |
| // act like the request was successfully sent. |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| if (request_headers_->BytesConsumed() >= request_headers_length_ && |
| ShouldTryReadingOnUploadError(result)) { |
| upload_error_ = result; |
| @@ -506,6 +517,7 @@ int HttpStreamParser::DoSendHeadersComplete(int result) { |
| } |
| // Finished sending the request. |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| return OK; |
| } |
| @@ -520,6 +532,7 @@ int HttpStreamParser::DoSendBody() { |
| if (request_->upload_data_stream->is_chunked() && sent_last_chunk_) { |
| // Finished sending the request. |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| return OK; |
| } |
| @@ -534,6 +547,7 @@ int HttpStreamParser::DoSendBodyComplete(int result) { |
| if (result < 0) { |
| // If |result| is an error that this should try reading after, stash the |
| // error for now and act like the request was successfully sent. |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| if (ShouldTryReadingOnUploadError(result)) { |
| upload_error_ = result; |
| return OK; |
| @@ -551,8 +565,10 @@ int HttpStreamParser::DoSendBodyComplete(int result) { |
| int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { |
| // |result| is the result of read from the request body from the last call to |
| // DoSendBody(). |
| - if (result < 0) |
| + if (result < 0) { |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| return result; |
| + } |
| // Chunked data needs to be encoded. |
| if (request_->upload_data_stream->is_chunked()) { |
| @@ -574,6 +590,7 @@ int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { |
| DCHECK(request_->upload_data_stream->IsEOF()); |
| DCHECK(!request_->upload_data_stream->is_chunked()); |
| // Finished sending the request. |
| + io_state_ = STATE_SEND_REQUEST_COMPLETE; |
| } else if (result > 0) { |
| request_body_send_buf_->DidAppend(result); |
| result = 0; |
| @@ -582,6 +599,12 @@ int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { |
| return result; |
| } |
| +int HttpStreamParser::DoSendRequestComplete(int result) { |
| + DCHECK_NE(result, ERR_IO_PENDING); |
| + FlushBuffers(); |
| + return result; |
| +} |
| + |
| int HttpStreamParser::DoReadHeaders() { |
| io_state_ = STATE_READ_HEADERS_COMPLETE; |
| @@ -1194,4 +1217,15 @@ void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { |
| HttpStatusLineValidator::STATUS_LINE_MAX); |
| } |
| +void HttpStreamParser::FlushBuffers() { |
|
mmenke
2016/07/12 16:13:41
nit: You can inline this in HttpStreamParser::DoS
|
| + request_headers_ = nullptr; |
| + request_body_send_buf_ = nullptr; |
| + request_body_read_buf_ = nullptr; |
| +} |
| + |
| +bool HttpStreamParser::SendRequestBuffersEmpty() { |
| + return request_headers_ == nullptr && request_body_send_buf_ == nullptr && |
| + request_body_send_buf_ == nullptr; |
| +} |
| + |
| } // namespace net |