Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 // We'll repurpose |request_headers_| to store the merged headers and | 253 // We'll repurpose |request_headers_| to store the merged headers and |
| 254 // body. | 254 // body. |
| 255 request_headers_ = new DrainableIOBuffer( | 255 request_headers_ = new DrainableIOBuffer( |
| 256 merged_request_headers_and_body, merged_size); | 256 merged_request_headers_and_body, merged_size); |
| 257 | 257 |
| 258 memcpy(request_headers_->data(), request.data(), request.size()); | 258 memcpy(request_headers_->data(), request.data(), request.size()); |
| 259 request_headers_->DidConsume(request.size()); | 259 request_headers_->DidConsume(request.size()); |
| 260 | 260 |
| 261 size_t todo = request_body_->size(); | 261 size_t todo = request_body_->size(); |
| 262 while (todo) { | 262 while (todo) { |
| 263 int consumed = request_body_->Read(request_headers_, todo); | 263 int consumed = request_body_->ReadSync(request_headers_, todo); |
| 264 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. | 264 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. |
| 265 request_headers_->DidConsume(consumed); | 265 request_headers_->DidConsume(consumed); |
| 266 todo -= consumed; | 266 todo -= consumed; |
| 267 } | 267 } |
| 268 DCHECK(request_body_->IsEOF()); | 268 DCHECK(request_body_->IsEOF()); |
| 269 // Reset the offset, so the buffer can be read from the beginning. | 269 // Reset the offset, so the buffer can be read from the beginning. |
| 270 request_headers_->SetOffset(0); | 270 request_headers_->SetOffset(0); |
| 271 did_merge = true; | 271 did_merge = true; |
| 272 | 272 |
| 273 net_log_.AddEvent( | 273 net_log_.AddEvent( |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 return connection_->socket()->Write(request_body_buf_, | 483 return connection_->socket()->Write(request_body_buf_, |
| 484 request_body_buf_->BytesRemaining(), | 484 request_body_buf_->BytesRemaining(), |
| 485 io_callback_); | 485 io_callback_); |
| 486 } | 486 } |
| 487 | 487 |
| 488 if (sent_last_chunk_) { | 488 if (sent_last_chunk_) { |
| 489 io_state_ = STATE_REQUEST_SENT; | 489 io_state_ = STATE_REQUEST_SENT; |
| 490 return OK; | 490 return OK; |
| 491 } | 491 } |
| 492 | 492 |
| 493 const int consumed = request_body_->Read(chunk_buf_, chunk_buf_->size()); | 493 const int consumed = request_body_->ReadSync(chunk_buf_, chunk_buf_->size()); |
| 494 if (consumed == 0) { // Reached the end. | 494 if (consumed == 0) { // Reached the end. |
| 495 DCHECK(request_body_->IsEOF()); | 495 DCHECK(request_body_->IsEOF()); |
| 496 request_body_buf_->Clear(); | 496 request_body_buf_->Clear(); |
| 497 const int chunk_length = EncodeChunk(base::StringPiece(), | 497 const int chunk_length = EncodeChunk(base::StringPiece(), |
| 498 request_body_buf_->data(), | 498 request_body_buf_->data(), |
| 499 request_body_buf_->capacity()); | 499 request_body_buf_->capacity()); |
| 500 request_body_buf_->DidAppend(chunk_length); | 500 request_body_buf_->DidAppend(chunk_length); |
| 501 sent_last_chunk_ = true; | 501 sent_last_chunk_ = true; |
| 502 } else if (consumed > 0) { | 502 } else if (consumed > 0) { |
| 503 // Encode and send the buffer as 1 chunk. | 503 // Encode and send the buffer as 1 chunk. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 527 | 527 |
| 528 // Send the remaining data in the request body buffer. | 528 // Send the remaining data in the request body buffer. |
| 529 request_body_buf_->DidConsume(result); | 529 request_body_buf_->DidConsume(result); |
| 530 if (request_body_buf_->BytesRemaining() > 0) { | 530 if (request_body_buf_->BytesRemaining() > 0) { |
| 531 return connection_->socket()->Write(request_body_buf_, | 531 return connection_->socket()->Write(request_body_buf_, |
| 532 request_body_buf_->BytesRemaining(), | 532 request_body_buf_->BytesRemaining(), |
| 533 io_callback_); | 533 io_callback_); |
| 534 } | 534 } |
| 535 | 535 |
| 536 request_body_buf_->Clear(); | 536 request_body_buf_->Clear(); |
| 537 const int consumed = request_body_->Read(request_body_buf_, | 537 const int consumed = request_body_->ReadSync(request_body_buf_, |
| 538 request_body_buf_->capacity()); | 538 request_body_buf_->capacity()); |
| 539 if (consumed == 0) { // Reached the end. | 539 if (consumed == 0) { // Reached the end. |
| 540 io_state_ = STATE_REQUEST_SENT; | 540 io_state_ = STATE_REQUEST_SENT; |
| 541 } else if (consumed > 0) { | 541 } else if (consumed > 0) { |
| 542 request_body_buf_->DidAppend(consumed); | 542 request_body_buf_->DidAppend(consumed); |
| 543 result = connection_->socket()->Write(request_body_buf_, | 543 result = connection_->socket()->Write(request_body_buf_, |
| 544 request_body_buf_->BytesRemaining(), | 544 request_body_buf_->BytesRemaining(), |
| 545 io_callback_); | 545 io_callback_); |
| 546 } else { | 546 } else { |
| 547 // UploadDataStream::Read() won't fail if not chunked. | 547 // UploadDataStream::Read() won't fail if not chunked. |
| 548 NOTREACHED(); | 548 NOTREACHED(); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 // If response_body_length_ is still -1, then we have to wait | 905 // If response_body_length_ is still -1, then we have to wait |
| 906 // for the server to close the connection. | 906 // for the server to close the connection. |
| 907 } | 907 } |
| 908 } | 908 } |
| 909 } | 909 } |
| 910 | 910 |
| 911 UploadProgress HttpStreamParser::GetUploadProgress() const { | 911 UploadProgress HttpStreamParser::GetUploadProgress() const { |
| 912 if (!request_body_.get()) | 912 if (!request_body_.get()) |
| 913 return UploadProgress(); | 913 return UploadProgress(); |
| 914 | 914 |
| 915 return UploadProgress(request_body_->position(), request_body_->size()); | 915 return UploadProgress(request_body_->position(), request_body_->size()); |
|
mmenke
2012/10/12 21:30:29
size will be 0 for chunked uploads, but position w
hashimoto
2012/10/15 11:21:37
Done for both HttpStreamParser and URLRequest.
| |
| 916 } | 916 } |
| 917 | 917 |
| 918 HttpResponseInfo* HttpStreamParser::GetResponseInfo() { | 918 HttpResponseInfo* HttpStreamParser::GetResponseInfo() { |
| 919 return response_; | 919 return response_; |
| 920 } | 920 } |
| 921 | 921 |
| 922 bool HttpStreamParser::IsResponseBodyComplete() const { | 922 bool HttpStreamParser::IsResponseBodyComplete() const { |
| 923 if (chunked_decoder_.get()) | 923 if (chunked_decoder_.get()) |
| 924 return chunked_decoder_->reached_eof(); | 924 return chunked_decoder_->reached_eof(); |
| 925 if (response_body_length_ != -1) | 925 if (response_body_length_ != -1) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1000 request_body->IsInMemory() && | 1000 request_body->IsInMemory() && |
| 1001 request_body->size() > 0) { | 1001 request_body->size() > 0) { |
| 1002 size_t merged_size = request_headers.size() + request_body->size(); | 1002 size_t merged_size = request_headers.size() + request_body->size(); |
| 1003 if (merged_size <= kMaxMergedHeaderAndBodySize) | 1003 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 1004 return true; | 1004 return true; |
| 1005 } | 1005 } |
| 1006 return false; | 1006 return false; |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 } // namespace net | 1009 } // namespace net |
| OLD | NEW |