| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (request_body_ != NULL && request_body_->is_chunked()) { | 132 if (request_body_ != NULL && request_body_->is_chunked()) { |
| 133 request_body_->set_chunk_callback(this); | 133 request_body_->set_chunk_callback(this); |
| 134 chunk_buf_ = new IOBuffer(chunk_buffer_size_); | 134 chunk_buf_ = new IOBuffer(chunk_buffer_size_); |
| 135 } | 135 } |
| 136 | 136 |
| 137 io_state_ = STATE_SENDING_HEADERS; | 137 io_state_ = STATE_SENDING_HEADERS; |
| 138 | 138 |
| 139 // If we have a small request body, then we'll merge with the headers into a | 139 // If we have a small request body, then we'll merge with the headers into a |
| 140 // single write. | 140 // single write. |
| 141 bool did_merge = false; | 141 bool did_merge = false; |
| 142 if (ShouldMerge(request, request_body_.get())) { | 142 if (ShouldMergeRequestHeadersAndBody(request, request_body_.get())) { |
| 143 size_t merged_size = request.size() + request_body->size(); | 143 size_t merged_size = request.size() + request_body->size(); |
| 144 scoped_refptr<IOBuffer> merged_request_headers_and_body( | 144 scoped_refptr<IOBuffer> merged_request_headers_and_body( |
| 145 new IOBuffer(merged_size)); | 145 new IOBuffer(merged_size)); |
| 146 // We'll repurpose |request_headers_| to store the merged headers and | 146 // We'll repurpose |request_headers_| to store the merged headers and |
| 147 // body. | 147 // body. |
| 148 request_headers_ = new DrainableIOBuffer( | 148 request_headers_ = new DrainableIOBuffer( |
| 149 merged_request_headers_and_body, merged_size); | 149 merged_request_headers_and_body, merged_size); |
| 150 | 150 |
| 151 char *buf = request_headers_->data(); | 151 char *buf = request_headers_->data(); |
| 152 memcpy(buf, request.data(), request.size()); | 152 memcpy(buf, request.data(), request.size()); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 cursor += payload.size(); | 804 cursor += payload.size(); |
| 805 } | 805 } |
| 806 // Add the trailing CRLF. | 806 // Add the trailing CRLF. |
| 807 memcpy(cursor, "\r\n", 2); | 807 memcpy(cursor, "\r\n", 2); |
| 808 cursor += 2; | 808 cursor += 2; |
| 809 | 809 |
| 810 return cursor - output; | 810 return cursor - output; |
| 811 } | 811 } |
| 812 | 812 |
| 813 // static | 813 // static |
| 814 bool HttpStreamParser::ShouldMerge(const std::string& request, | 814 bool HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 815 const UploadDataStream* request_body) { | 815 const std::string& request_headers, |
| 816 const UploadDataStream* request_body) { |
| 816 if (request_body != NULL && | 817 if (request_body != NULL && |
| 817 // IsInMemory() ensures that the request body is not chunked. | 818 // IsInMemory() ensures that the request body is not chunked. |
| 818 request_body->IsInMemory() && | 819 request_body->IsInMemory() && |
| 819 request_body->size() > 0) { | 820 request_body->size() > 0) { |
| 820 size_t merged_size = request.size() + request_body->size(); | 821 size_t merged_size = request_headers.size() + request_body->size(); |
| 821 if (merged_size <= kMaxMergedHeaderAndBodySize) | 822 if (merged_size <= kMaxMergedHeaderAndBodySize) |
| 822 return true; | 823 return true; |
| 823 } | 824 } |
| 824 return false; | 825 return false; |
| 825 } | 826 } |
| 826 | 827 |
| 827 } // namespace net | 828 } // namespace net |
| OLD | NEW |