@@ -474,8 +474,6 @@ static struct {
474
474
};
475
475
#undef HTTP_STRERROR_GEN
476
476
477
- int http_message_needs_eof (const http_parser * parser );
478
-
479
477
/* Our URL parser.
480
478
*
481
479
* This is designed to be shared by http_parser_execute() for URL validation,
@@ -887,6 +885,12 @@ size_t http_parser_execute (http_parser *parser,
887
885
888
886
case s_res_status_start :
889
887
{
888
+ /* See RFC 7230 section 3.3.3, step 1 */
889
+ if (parser -> status_code / 100 == 1 || /* 1xx e.g. Continue */
890
+ parser -> status_code == 204 || /* No Content */
891
+ parser -> status_code == 304 ) { /* Not Modified */
892
+ parser -> flags |= F_SKIPBODY ;
893
+ }
890
894
MARK (status );
891
895
UPDATE_STATE (s_res_status );
892
896
parser -> index = 0 ;
@@ -1856,7 +1860,7 @@ size_t http_parser_execute (http_parser *parser,
1856
1860
/* Content-Length header given and non-zero */
1857
1861
UPDATE_STATE (s_body_identity );
1858
1862
} else {
1859
- if (! http_message_needs_eof ( parser ) ) {
1863
+ if (parser -> type == HTTP_REQUEST ) {
1860
1864
/* Assume content-length 0 - read the next */
1861
1865
UPDATE_STATE (NEW_MESSAGE ());
1862
1866
CALLBACK_NOTIFY (message_complete );
@@ -2084,30 +2088,6 @@ size_t http_parser_execute (http_parser *parser,
2084
2088
}
2085
2089
2086
2090
2087
- /* Does the parser need to see an EOF to find the end of the message? */
2088
- int
2089
- http_message_needs_eof (const http_parser * parser )
2090
- {
2091
- if (parser -> type == HTTP_REQUEST ) {
2092
- return 0 ;
2093
- }
2094
-
2095
- /* See RFC 2616 section 4.4 */
2096
- if (parser -> status_code / 100 == 1 || /* 1xx e.g. Continue */
2097
- parser -> status_code == 204 || /* No Content */
2098
- parser -> status_code == 304 || /* Not Modified */
2099
- parser -> flags & F_SKIPBODY ) { /* response to a HEAD request */
2100
- return 0 ;
2101
- }
2102
-
2103
- if ((parser -> flags & F_CHUNKED ) || parser -> content_length != ULLONG_MAX ) {
2104
- return 0 ;
2105
- }
2106
-
2107
- return 1 ;
2108
- }
2109
-
2110
-
2111
2091
int
2112
2092
http_should_keep_alive (const http_parser * parser )
2113
2093
{
@@ -2123,7 +2103,19 @@ http_should_keep_alive (const http_parser *parser)
2123
2103
}
2124
2104
}
2125
2105
2126
- return !http_message_needs_eof (parser );
2106
+ /* RFC 7230 section 3.3.3, step 7:
2107
+ * ... this is a response message without a declared message body length, so
2108
+ * the message body length is determined by the number of octets received
2109
+ * prior to the server closing the connection.
2110
+ */
2111
+ if (parser -> type == HTTP_RESPONSE &&
2112
+ !(parser -> flags & F_SKIPBODY ) &&
2113
+ !(parser -> flags & F_CHUNKED ) &&
2114
+ parser -> content_length == ULLONG_MAX ) {
2115
+ return 0 ;
2116
+ }
2117
+
2118
+ return 1 ;
2127
2119
}
2128
2120
2129
2121
0 commit comments