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

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

Issue 1169603002: Update references to RFC2616. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Describe the 205 case. Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 // Prevent growing the headers buffer indefinitely. 833 // Prevent growing the headers buffer indefinitely.
834 if (read_buf_->offset() >= kMaxHeaderBufSize) { 834 if (read_buf_->offset() >= kMaxHeaderBufSize) {
835 io_state_ = STATE_DONE; 835 io_state_ = STATE_DONE;
836 return ERR_RESPONSE_HEADERS_TOO_BIG; 836 return ERR_RESPONSE_HEADERS_TOO_BIG;
837 } 837 }
838 } else { 838 } else {
839 CalculateResponseBodySize(); 839 CalculateResponseBodySize();
840 // If the body is zero length, the caller may not call ReadResponseBody, 840 // If the body is zero length, the caller may not call ReadResponseBody,
841 // which is where any extra data is copied to read_buf_, so we move the 841 // which is where any extra data is copied to read_buf_, so we move the
842 // data here. 842 // data here.
843 if (response_body_length_ == 0) { 843 if (response_body_length_ == 0) {
wtc 2015/06/05 01:51:05 This is the code that depends on CalculateResponse
844 int extra_bytes = read_buf_->offset() - end_of_header_offset; 844 int extra_bytes = read_buf_->offset() - end_of_header_offset;
845 if (extra_bytes) { 845 if (extra_bytes) {
846 CHECK_GT(extra_bytes, 0); 846 CHECK_GT(extra_bytes, 0);
847 memmove(read_buf_->StartOfBuffer(), 847 memmove(read_buf_->StartOfBuffer(),
848 read_buf_->StartOfBuffer() + end_of_header_offset, 848 read_buf_->StartOfBuffer() + end_of_header_offset,
849 extra_bytes); 849 extra_bytes);
850 } 850 }
851 read_buf_->SetCapacity(extra_bytes); 851 read_buf_->SetCapacity(extra_bytes);
852 if (response_->headers->response_code() / 100 == 1) { 852 if (response_->headers->response_code() / 100 == 1) {
853 // After processing a 1xx response, the caller will ask for the next 853 // After processing a 1xx response, the caller will ask for the next
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 << "\n\"" 956 << "\n\""
957 << " headers = \"" 957 << " headers = \""
958 << GetResponseHeaderLines(*response_->headers.get()) << "\""; 958 << GetResponseHeaderLines(*response_->headers.get()) << "\"";
959 return OK; 959 return OK;
960 } 960 }
961 961
962 void HttpStreamParser::CalculateResponseBodySize() { 962 void HttpStreamParser::CalculateResponseBodySize() {
963 // Figure how to determine EOF: 963 // Figure how to determine EOF:
964 964
965 // For certain responses, we know the content length is always 0. From 965 // For certain responses, we know the content length is always 0. From
966 // RFC 2616 Section 4.3 Message Body: 966 // RFC 7230 Section 3.3 Message Body:
967 // 967 //
968 // For response messages, whether or not a message-body is included with 968 // The presence of a message body in a response depends on both the
969 // a message is dependent on both the request method and the response 969 // request method to which it is responding and the response status code
970 // status code (section 6.1.1). All responses to the HEAD request method 970 // (Section 3.1.2). Responses to the HEAD request method (Section 4.3.2
971 // MUST NOT include a message-body, even though the presence of entity- 971 // of [RFC7231]) never include a message body because the associated
972 // header fields might lead one to believe they do. All 1xx 972 // response header fields (e.g., Transfer-Encoding, Content-Length,
973 // (informational), 204 (no content), and 304 (not modified) responses 973 // etc.), if present, indicate only what their values would have been if
974 // MUST NOT include a message-body. All other responses do include a 974 // the request method had been GET (Section 4.3.1 of [RFC7231]). 2xx
975 // message-body, although it MAY be of zero length. 975 // (Successful) responses to a CONNECT request method (Section 4.3.6 of
976 // [RFC7231]) switch to tunnel mode instead of having a message body.
wtc 2015/06/05 01:51:05 I studied the relevant code. It seems useful to se
Bence 2015/06/05 11:28:33 I think this will naturally come up if someone wan
977 // All 1xx (Informational), 204 (No Content), and 304 (Not Modified)
978 // responses do not include a message body. All other responses do
979 // include a message body, although the body might be of zero length.
980 //
981 // From RFC 7231 Section 6.3.6 205 Reset Content:
982 //
983 // Since the 205 status code implies that no additional content will be
984 // provided, a server MUST NOT generate a payload in a 205 response. In
985 // other words, a server MUST do one of the following for a 205
wtc 2015/06/05 01:51:04 Chris: do you think we need to quote the entire pa
Bence 2015/06/05 11:28:33 I think the first sentence is enough. Even better
cbentzel 2015/06/05 14:07:30 Agree that first sentence is enough. Thanks for fi
wtc 2015/06/05 17:28:50 Done.
986 // response: a) indicate a zero-length body for the response by
987 // including a Content-Length header field with a value of 0; b)
988 // indicate a zero-length payload for the response by including a
989 // Transfer-Encoding header field with a value of chunked and a message
990 // body consisting of a single chunk of zero-length; or, c) close the
991 // connection immediately after sending the blank line terminating the
992 // header section.
976 if (response_->headers->response_code() / 100 == 1) { 993 if (response_->headers->response_code() / 100 == 1) {
977 response_body_length_ = 0; 994 response_body_length_ = 0;
978 } else { 995 } else {
979 switch (response_->headers->response_code()) { 996 switch (response_->headers->response_code()) {
980 case 204: // No Content 997 case 204: // No Content
981 case 205: // Reset Content 998 case 205: // Reset Content
982 case 304: // Not Modified 999 case 304: // Not Modified
983 response_body_length_ = 0; 1000 response_body_length_ = 0;
984 break; 1001 break;
985 } 1002 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 request_body->IsInMemory() && 1105 request_body->IsInMemory() &&
1089 request_body->size() > 0) { 1106 request_body->size() > 0) {
1090 uint64 merged_size = request_headers.size() + request_body->size(); 1107 uint64 merged_size = request_headers.size() + request_body->size();
1091 if (merged_size <= kMaxMergedHeaderAndBodySize) 1108 if (merged_size <= kMaxMergedHeaderAndBodySize)
1092 return true; 1109 return true;
1093 } 1110 }
1094 return false; 1111 return false;
1095 } 1112 }
1096 1113
1097 } // namespace net 1114 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698