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

Unified Diff: net/http/http_stream_parser.cc

Issue 25312002: net: don't preserve 1xx responses in parser buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« net/http/http_stream_parser.h ('K') | « net/http/http_stream_parser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_stream_parser.cc
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index e53aafdac1cfd4871dd41d3cd2989d1ed6e1de27..9067bff9af02b0173446be685a1089b20dd3ee88 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -304,8 +304,9 @@ int HttpStreamParser::ReadResponseHeaders(const CompletionCallback& callback) {
if (read_buf_->offset() > 0) {
// Simulate the state where the data was just read from the socket.
- result = read_buf_->offset() - read_buf_unused_offset_;
- read_buf_->set_offset(read_buf_unused_offset_);
+ DCHECK_EQ(0, read_buf_unused_offset_);
SkyLined 2013/09/30 18:27:47 Should we move this DCHECK to the start of the fun
agl 2013/09/30 20:59:28 Done.
+ result = read_buf_->offset();
+ read_buf_->set_offset(0);
}
if (result > 0)
io_state_ = STATE_READ_HEADERS_COMPLETE;
@@ -580,7 +581,8 @@ int HttpStreamParser::DoReadHeadersComplete(int result) {
if (end_of_header_offset == -1) {
io_state_ = STATE_READ_HEADERS;
// Prevent growing the headers buffer indefinitely.
- if (read_buf_->offset() - read_buf_unused_offset_ >= kMaxHeaderBufSize) {
+ DCHECK_EQ(0, read_buf_unused_offset_);
SkyLined 2013/09/30 18:27:47 Should we move this DCHECK to the start of the fun
agl 2013/09/30 20:59:28 Done.
+ if (read_buf_->offset() >= kMaxHeaderBufSize) {
io_state_ = STATE_DONE;
return ERR_RESPONSE_HEADERS_TOO_BIG;
}
@@ -588,32 +590,34 @@ int HttpStreamParser::DoReadHeadersComplete(int result) {
// Note where the headers stop.
read_buf_unused_offset_ = end_of_header_offset;
SkyLined 2013/09/30 18:27:47 This is only needed if the response contains a bod
agl 2013/09/30 20:59:28 Done.
- if (response_->headers->response_code() / 100 == 1) {
- // After processing a 1xx response, the caller will ask for the next
- // header, so reset state to support that. We don't just skip these
- // completely because 1xx codes aren't acceptable when establishing a
- // tunnel.
- io_state_ = STATE_REQUEST_SENT;
- response_header_start_offset_ = -1;
- } else {
- io_state_ = STATE_BODY_PENDING;
- CalculateResponseBodySize();
- // If the body is 0, the caller may not call ReadResponseBody, which
- // is where any extra data is copied to read_buf_, so we move the
- // data here and transition to DONE.
- if (response_body_length_ == 0) {
+ CalculateResponseBodySize();
+ // If the body is 0, the caller may not call ReadResponseBody, which
+ // is where any extra data is copied to read_buf_, so we move the
+ // data here.
+ if (response_body_length_ == 0) {
+ int extra_bytes = read_buf_->offset() - read_buf_unused_offset_;
+ if (extra_bytes) {
+ CHECK_GT(extra_bytes, 0);
+ memmove(read_buf_->StartOfBuffer(),
+ read_buf_->StartOfBuffer() + read_buf_unused_offset_,
+ extra_bytes);
+ }
+ read_buf_->SetCapacity(extra_bytes);
+ read_buf_unused_offset_ = 0;
+ if (response_->headers->response_code() / 100 == 1) {
+ // After processing a 1xx response, the caller will ask for the next
+ // header, so reset state to support that. We don't just skip these
+ // completely because 1xx codes aren't acceptable when establishing a
+ // tunnel.
+ response_header_start_offset_ = -1;
+ response_body_length_ = -1;
+ io_state_ = STATE_REQUEST_SENT;
+ } else {
io_state_ = STATE_DONE;
- int extra_bytes = read_buf_->offset() - read_buf_unused_offset_;
- if (extra_bytes) {
- CHECK_GT(extra_bytes, 0);
- memmove(read_buf_->StartOfBuffer(),
- read_buf_->StartOfBuffer() + read_buf_unused_offset_,
- extra_bytes);
- }
- read_buf_->SetCapacity(extra_bytes);
- read_buf_unused_offset_ = 0;
- return OK;
}
+ return OK;
+ } else {
+ io_state_ = STATE_BODY_PENDING;
}
}
return result;
@@ -754,16 +758,16 @@ int HttpStreamParser::ParseResponseHeaders() {
// Look for the start of the status line, if it hasn't been found yet.
if (response_header_start_offset_ < 0) {
+ DCHECK_EQ(0, read_buf_unused_offset_);
SkyLined 2013/09/30 18:27:47 Should we move this DCHECK to the start of the fun
agl 2013/09/30 20:59:28 Done.
response_header_start_offset_ = HttpUtil::LocateStartOfStatusLine(
- read_buf_->StartOfBuffer() + read_buf_unused_offset_,
- read_buf_->offset() - read_buf_unused_offset_);
+ read_buf_->StartOfBuffer(), read_buf_->offset());
}
if (response_header_start_offset_ >= 0) {
- end_offset = HttpUtil::LocateEndOfHeaders(
- read_buf_->StartOfBuffer() + read_buf_unused_offset_,
- read_buf_->offset() - read_buf_unused_offset_,
- response_header_start_offset_);
+ DCHECK_EQ(0, read_buf_unused_offset_);
SkyLined 2013/09/30 18:27:47 Should we move this DCHECK to the start of the fun
agl 2013/09/30 20:59:28 Done.
+ end_offset = HttpUtil::LocateEndOfHeaders(read_buf_->StartOfBuffer(),
+ read_buf_->offset(),
+ response_header_start_offset_);
} else if (read_buf_->offset() - read_buf_unused_offset_ >= 8) {
// Enough data to decide that this is an HTTP/0.9 response.
// 8 bytes = (4 bytes of junk) + "http".length()
@@ -776,7 +780,8 @@ int HttpStreamParser::ParseResponseHeaders() {
int rv = DoParseResponseHeaders(end_offset);
if (rv < 0)
return rv;
- return end_offset + read_buf_unused_offset_;
+ DCHECK_EQ(0, read_buf_unused_offset_);
SkyLined 2013/09/30 18:27:47 Should we move this DCHECK to the start of the fun
agl 2013/09/30 20:59:28 Done.
+ return end_offset;
}
int HttpStreamParser::DoParseResponseHeaders(int end_offset) {
@@ -830,13 +835,16 @@ void HttpStreamParser::CalculateResponseBodySize() {
// (informational), 204 (no content), and 304 (not modified) responses
// MUST NOT include a message-body. All other responses do include a
// message-body, although it MAY be of zero length.
- switch (response_->headers->response_code()) {
- // Note that 1xx was already handled earlier.
- case 204: // No Content
- case 205: // Reset Content
- case 304: // Not Modified
- response_body_length_ = 0;
- break;
+ if (response_->headers->response_code() / 100 == 1) {
+ response_body_length_ = 0;
+ } else {
+ switch (response_->headers->response_code()) {
+ case 204: // No Content
+ case 205: // Reset Content
+ case 304: // Not Modified
+ response_body_length_ = 0;
+ break;
+ }
}
if (request_->method == "HEAD")
response_body_length_ = 0;
« net/http/http_stream_parser.h ('K') | « net/http/http_stream_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698