Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: net/http/http_stream_parser.cc

Issue 9270030: net: Don't merge HTTP headers and body if the body is not in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 (request_body_ != NULL && 142 if (ShouldMerge(request, request_body_.get())) {
143 !request_body_->is_chunked() && 143 size_t merged_size = request.size() + request_body->size();
144 request_body_->size() > 0) { 144 scoped_refptr<IOBuffer> merged_request_headers_and_body(
145 size_t merged_size = request.size() + request_body_->size(); 145 new IOBuffer(merged_size));
146 if (merged_size <= kMaxMergedHeaderAndBodySize) { 146 // We'll repurpose |request_headers_| to store the merged headers and
147 scoped_refptr<IOBuffer> merged_request_headers_and_body( 147 // body.
148 new IOBuffer(merged_size)); 148 request_headers_ = new DrainableIOBuffer(
149 // We'll repurpose |request_headers_| to store the merged headers and 149 merged_request_headers_and_body, merged_size);
150 // body.
151 request_headers_ = new DrainableIOBuffer(
152 merged_request_headers_and_body, merged_size);
153 150
154 char *buf = request_headers_->data(); 151 char *buf = request_headers_->data();
155 memcpy(buf, request.data(), request.size()); 152 memcpy(buf, request.data(), request.size());
156 buf += request.size(); 153 buf += request.size();
157 154
158 size_t todo = request_body_->size(); 155 size_t todo = request_body_->size();
159 while (todo) { 156 while (todo) {
160 size_t buf_len = request_body_->buf_len(); 157 size_t buf_len = request_body_->buf_len();
161 memcpy(buf, request_body_->buf()->data(), buf_len); 158 memcpy(buf, request_body_->buf()->data(), buf_len);
162 todo -= buf_len; 159 todo -= buf_len;
163 buf += buf_len; 160 buf += buf_len;
164 request_body_->MarkConsumedAndFillBuffer(buf_len); 161 request_body_->MarkConsumedAndFillBuffer(buf_len);
165 } 162 }
166 DCHECK(request_body_->eof()); 163 DCHECK(request_body_->eof());
167 164
168 did_merge = true; 165 did_merge = true;
169 }
170 } 166 }
171 167
172 if (!did_merge) { 168 if (!did_merge) {
173 // If we didn't merge the body with the headers, then |request_headers_| 169 // If we didn't merge the body with the headers, then |request_headers_|
174 // contains just the HTTP headers. 170 // contains just the HTTP headers.
175 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); 171 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request));
176 request_headers_ = new DrainableIOBuffer(headers_io_buf, 172 request_headers_ = new DrainableIOBuffer(headers_io_buf,
177 headers_io_buf->size()); 173 headers_io_buf->size());
178 } 174 }
179 175
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 memcpy(cursor, payload.data(), payload.size()); 803 memcpy(cursor, payload.data(), payload.size());
808 cursor += payload.size(); 804 cursor += payload.size();
809 } 805 }
810 // Add the trailing CRLF. 806 // Add the trailing CRLF.
811 memcpy(cursor, "\r\n", 2); 807 memcpy(cursor, "\r\n", 2);
812 cursor += 2; 808 cursor += 2;
813 809
814 return cursor - output; 810 return cursor - output;
815 } 811 }
816 812
813 // static
814 bool HttpStreamParser::ShouldMerge(const std::string& request,
815 const UploadDataStream* request_body) {
816 if (request_body != NULL &&
817 // IsInMemory() ensures that the request body is not chunked.
wtc 2012/01/24 19:08:04 This comment doesn't seem useful -- or it should a
818 request_body->IsInMemory() &&
819 request_body->size() > 0) {
820 size_t merged_size = request.size() + request_body->size();
821 if (merged_size <= kMaxMergedHeaderAndBodySize)
822 return true;
823 }
824 return false;
825 }
826
817 } // namespace net 827 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698