| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // We'll repurpose |request_headers_| to store the merged headers and | 240 // We'll repurpose |request_headers_| to store the merged headers and |
| 241 // body. | 241 // body. |
| 242 request_headers_ = new DrainableIOBuffer( | 242 request_headers_ = new DrainableIOBuffer( |
| 243 merged_request_headers_and_body, merged_size); | 243 merged_request_headers_and_body, merged_size); |
| 244 | 244 |
| 245 memcpy(request_headers_->data(), request.data(), request.size()); | 245 memcpy(request_headers_->data(), request.data(), request.size()); |
| 246 request_headers_->DidConsume(request.size()); | 246 request_headers_->DidConsume(request.size()); |
| 247 | 247 |
| 248 size_t todo = request_body_->size(); | 248 size_t todo = request_body_->size(); |
| 249 while (todo) { | 249 while (todo) { |
| 250 int consumed = request_body_->Read(request_headers_, todo); | 250 int consumed = request_body_->ReadSync(request_headers_, todo); |
| 251 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. | 251 DCHECK_GT(consumed, 0); // Read() won't fail if not chunked. |
| 252 request_headers_->DidConsume(consumed); | 252 request_headers_->DidConsume(consumed); |
| 253 todo -= consumed; | 253 todo -= consumed; |
| 254 } | 254 } |
| 255 DCHECK(request_body_->IsEOF()); | 255 DCHECK(request_body_->IsEOF()); |
| 256 // Reset the offset, so the buffer can be read from the beginning. | 256 // Reset the offset, so the buffer can be read from the beginning. |
| 257 request_headers_->SetOffset(0); | 257 request_headers_->SetOffset(0); |
| 258 | 258 |
| 259 did_merge = true; | 259 did_merge = true; |
| 260 } | 260 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 return connection_->socket()->Write(request_body_buf_, | 452 return connection_->socket()->Write(request_body_buf_, |
| 453 request_body_buf_->BytesRemaining(), | 453 request_body_buf_->BytesRemaining(), |
| 454 io_callback_); | 454 io_callback_); |
| 455 } | 455 } |
| 456 | 456 |
| 457 if (sent_last_chunk_) { | 457 if (sent_last_chunk_) { |
| 458 io_state_ = STATE_REQUEST_SENT; | 458 io_state_ = STATE_REQUEST_SENT; |
| 459 return OK; | 459 return OK; |
| 460 } | 460 } |
| 461 | 461 |
| 462 const int consumed = request_body_->Read(chunk_buf_, chunk_buf_->size()); | 462 const int consumed = request_body_->ReadSync(chunk_buf_, chunk_buf_->size()); |
| 463 if (consumed == 0) { // Reached the end. | 463 if (consumed == 0) { // Reached the end. |
| 464 DCHECK(request_body_->IsEOF()); | 464 DCHECK(request_body_->IsEOF()); |
| 465 request_body_buf_->Clear(); | 465 request_body_buf_->Clear(); |
| 466 const int chunk_length = EncodeChunk(base::StringPiece(), | 466 const int chunk_length = EncodeChunk(base::StringPiece(), |
| 467 request_body_buf_->data(), | 467 request_body_buf_->data(), |
| 468 request_body_buf_->capacity()); | 468 request_body_buf_->capacity()); |
| 469 request_body_buf_->DidAppend(chunk_length); | 469 request_body_buf_->DidAppend(chunk_length); |
| 470 sent_last_chunk_ = true; | 470 sent_last_chunk_ = true; |
| 471 } else if (consumed > 0) { | 471 } else if (consumed > 0) { |
| 472 // Encode and send the buffer as 1 chunk. | 472 // Encode and send the buffer as 1 chunk. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 496 | 496 |
| 497 // Send the remaining data in the request body buffer. | 497 // Send the remaining data in the request body buffer. |
| 498 request_body_buf_->DidConsume(result); | 498 request_body_buf_->DidConsume(result); |
| 499 if (request_body_buf_->BytesRemaining() > 0) { | 499 if (request_body_buf_->BytesRemaining() > 0) { |
| 500 return connection_->socket()->Write(request_body_buf_, | 500 return connection_->socket()->Write(request_body_buf_, |
| 501 request_body_buf_->BytesRemaining(), | 501 request_body_buf_->BytesRemaining(), |
| 502 io_callback_); | 502 io_callback_); |
| 503 } | 503 } |
| 504 | 504 |
| 505 request_body_buf_->Clear(); | 505 request_body_buf_->Clear(); |
| 506 const int consumed = request_body_->Read(request_body_buf_, | 506 const int consumed = request_body_->ReadSync(request_body_buf_, |
| 507 request_body_buf_->capacity()); | 507 request_body_buf_->capacity()); |
| 508 if (consumed == 0) { // Reached the end. | 508 if (consumed == 0) { // Reached the end. |
| 509 io_state_ = STATE_REQUEST_SENT; | 509 io_state_ = STATE_REQUEST_SENT; |
| 510 } else if (consumed > 0) { | 510 } else if (consumed > 0) { |
| 511 request_body_buf_->DidAppend(consumed); | 511 request_body_buf_->DidAppend(consumed); |
| 512 result = connection_->socket()->Write(request_body_buf_, | 512 result = connection_->socket()->Write(request_body_buf_, |
| 513 request_body_buf_->BytesRemaining(), | 513 request_body_buf_->BytesRemaining(), |
| 514 io_callback_); | 514 io_callback_); |
| 515 } else { | 515 } else { |
| 516 // UploadDataStream::Read() won't fail if not chunked. | 516 // UploadDataStream::Read() won't fail if not chunked. |
| 517 NOTREACHED(); | 517 NOTREACHED(); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 request_body->IsInMemory() && | 969 request_body->IsInMemory() && |
| 970 request_body->size() > 0) { | 970 request_body->size() > 0) { |
| 971 size_t merged_size = request_headers.size() + request_body->size(); | 971 size_t merged_size = request_headers.size() + request_body->size(); |
| 972 if (merged_size <= kMaxMergedHeaderAndBodySize) | 972 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 973 return true; | 973 return true; |
| 974 } | 974 } |
| 975 return false; | 975 return false; |
| 976 } | 976 } |
| 977 | 977 |
| 978 } // namespace net | 978 } // namespace net |
| OLD | NEW |