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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_stream_parser.cc
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index a6e3cafb985a132b68b45ea1221414ed9a7b696d..7966889e1f38c24c3da9e89877a0bb4b4f8df360 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -139,34 +139,30 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
// If we have a small request body, then we'll merge with the headers into a
// single write.
bool did_merge = false;
- if (request_body_ != NULL &&
- !request_body_->is_chunked() &&
- request_body_->size() > 0) {
- size_t merged_size = request.size() + request_body_->size();
- if (merged_size <= kMaxMergedHeaderAndBodySize) {
- scoped_refptr<IOBuffer> merged_request_headers_and_body(
- new IOBuffer(merged_size));
- // We'll repurpose |request_headers_| to store the merged headers and
- // body.
- request_headers_ = new DrainableIOBuffer(
- merged_request_headers_and_body, merged_size);
-
- char *buf = request_headers_->data();
- memcpy(buf, request.data(), request.size());
- buf += request.size();
-
- size_t todo = request_body_->size();
- while (todo) {
- size_t buf_len = request_body_->buf_len();
- memcpy(buf, request_body_->buf()->data(), buf_len);
- todo -= buf_len;
- buf += buf_len;
- request_body_->MarkConsumedAndFillBuffer(buf_len);
- }
- DCHECK(request_body_->eof());
-
- did_merge = true;
+ if (ShouldMerge(request, request_body_.get())) {
+ size_t merged_size = request.size() + request_body->size();
+ scoped_refptr<IOBuffer> merged_request_headers_and_body(
+ new IOBuffer(merged_size));
+ // We'll repurpose |request_headers_| to store the merged headers and
+ // body.
+ request_headers_ = new DrainableIOBuffer(
+ merged_request_headers_and_body, merged_size);
+
+ char *buf = request_headers_->data();
+ memcpy(buf, request.data(), request.size());
+ buf += request.size();
+
+ size_t todo = request_body_->size();
+ while (todo) {
+ size_t buf_len = request_body_->buf_len();
+ memcpy(buf, request_body_->buf()->data(), buf_len);
+ todo -= buf_len;
+ buf += buf_len;
+ request_body_->MarkConsumedAndFillBuffer(buf_len);
}
+ DCHECK(request_body_->eof());
+
+ did_merge = true;
}
if (!did_merge) {
@@ -814,4 +810,18 @@ int HttpStreamParser::EncodeChunk(const base::StringPiece& payload,
return cursor - output;
}
+// static
+bool HttpStreamParser::ShouldMerge(const std::string& request,
+ const UploadDataStream* request_body) {
+ if (request_body != NULL &&
+ // 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
+ request_body->IsInMemory() &&
+ request_body->size() > 0) {
+ size_t merged_size = request.size() + request_body->size();
+ if (merged_size <= kMaxMergedHeaderAndBodySize)
+ return true;
+ }
+ return false;
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698