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 2a3fb156d585a72561361b961458c7657b5501d9..62a97592888a16771e5046b6866e851d23f03218 100644 |
| --- a/net/http/http_stream_parser.cc |
| +++ b/net/http/http_stream_parser.cc |
| @@ -67,6 +67,8 @@ int HttpStreamParser::SendRequest(const std::string& request_line, |
| request_headers_ = new DrainableIOBuffer(headers_io_buf, |
| headers_io_buf->size()); |
| request_body_.reset(request_body); |
| + if (request_body_.get() && request_body_->is_chunked()) |
|
wtc
2011/01/20 00:29:47
Nit: request_body_.get() => request_body_ != NULL
|
| + request_body_->set_chunk_callback(this); |
| io_state_ = STATE_SENDING_HEADERS; |
| int result = DoLoop(OK); |
| @@ -143,6 +145,15 @@ void HttpStreamParser::OnIOComplete(int result) { |
| } |
| } |
| +void HttpStreamParser::OnChunkAvailable() { |
| + // This method may get called in any state so check before processing the new |
|
wtc
2011/01/20 00:29:47
If you add the DCHECK vandebo suggested, please up
|
| + // data. If we were still initializing or sending headers, we will |
| + // automatically start reading the chunks once we get into STATE_SENDING_BODY |
| + // so nothing to do here. |
|
vandebo (ex-Chrome)
2011/01/18 21:51:17
nit: You could DCHECK(io_state_ == STATE_SENDING_
|
| + if (io_state_ == STATE_SENDING_BODY) |
| + OnIOComplete(0); |
| +} |
| + |
| int HttpStreamParser::DoLoop(int result) { |
| bool can_do_more = true; |
| do { |
| @@ -213,7 +224,7 @@ int HttpStreamParser::DoSendHeaders(int result) { |
| COALESCE_POTENTIAL_MAX = 30 // Various cases of coalasced savings. |
| }; |
| size_t coalesce = HEADER_ONLY; |
| - if (request_body_ != NULL) { |
| + if (request_body_ != NULL && !request_body_->is_chunked()) { |
| const size_t kBytesPerPacket = 1430; |
| uint64 body_packets = (request_body_->size() + kBytesPerPacket - 1) / |
| kBytesPerPacket; |
| @@ -236,7 +247,8 @@ int HttpStreamParser::DoSendHeaders(int result) { |
| result = connection_->socket()->Write(request_headers_, |
| bytes_remaining, |
| &io_callback_); |
| - } else if (request_body_ != NULL && request_body_->size()) { |
| + } else if (request_body_ != NULL && |
| + (request_body_->is_chunked() || request_body_->size())) { |
| io_state_ = STATE_SENDING_BODY; |
| result = OK; |
| } else { |
| @@ -251,8 +263,13 @@ int HttpStreamParser::DoSendBody(int result) { |
| if (!request_body_->eof()) { |
| int buf_len = static_cast<int>(request_body_->buf_len()); |
| - result = connection_->socket()->Write(request_body_->buf(), buf_len, |
| - &io_callback_); |
| + if (buf_len) { |
| + result = connection_->socket()->Write(request_body_->buf(), buf_len, |
| + &io_callback_); |
| + } else { |
| + // More POST data is to come hence wait for the callback. |
| + result = ERR_IO_PENDING; |
| + } |
| } else { |
| io_state_ = STATE_REQUEST_SENT; |
| } |