@@ -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 ;
@@ -1859,7 +1863,7 @@ size_t http_parser_execute (http_parser *parser,
1859
1863
/* Content-Length header given and non-zero */
1860
1864
UPDATE_STATE (s_body_identity );
1861
1865
} else {
1862
- if (! http_message_needs_eof ( parser ) ) {
1866
+ if (parser -> type == HTTP_REQUEST ) {
1863
1867
/* Assume content-length 0 - read the next */
1864
1868
UPDATE_STATE (NEW_MESSAGE ());
1865
1869
CALLBACK_NOTIFY (message_complete );
@@ -2087,30 +2091,6 @@ size_t http_parser_execute (http_parser *parser,
2087
2091
}
2088
2092
2089
2093
2090
- /* Does the parser need to see an EOF to find the end of the message? */
2091
- int
2092
- http_message_needs_eof (const http_parser * parser )
2093
- {
2094
- if (parser -> type == HTTP_REQUEST ) {
2095
- return 0 ;
2096
- }
2097
-
2098
- /* See RFC 2616 section 4.4 */
2099
- if (parser -> status_code / 100 == 1 || /* 1xx e.g. Continue */
2100
- parser -> status_code == 204 || /* No Content */
2101
- parser -> status_code == 304 || /* Not Modified */
2102
- parser -> flags & F_SKIPBODY ) { /* response to a HEAD request */
2103
- return 0 ;
2104
- }
2105
-
2106
- if ((parser -> flags & F_CHUNKED ) || parser -> content_length != ULLONG_MAX ) {
2107
- return 0 ;
2108
- }
2109
-
2110
- return 1 ;
2111
- }
2112
-
2113
-
2114
2094
int
2115
2095
http_should_keep_alive (const http_parser * parser )
2116
2096
{
@@ -2126,7 +2106,19 @@ http_should_keep_alive (const http_parser *parser)
2126
2106
}
2127
2107
}
2128
2108
2129
- return !http_message_needs_eof (parser );
2109
+ /* RFC 7230 section 3.3.3, step 7:
2110
+ * ... this is a response message without a declared message body length, so
2111
+ * the message body length is determined by the number of octets received
2112
+ * prior to the server closing the connection.
2113
+ */
2114
+ if (parser -> type == HTTP_RESPONSE &&
2115
+ !(parser -> flags & F_SKIPBODY ) &&
2116
+ !(parser -> flags & F_CHUNKED ) &&
2117
+ parser -> content_length == ULLONG_MAX ) {
2118
+ return 0 ;
2119
+ }
2120
+
2121
+ return 1 ;
2130
2122
}
2131
2123
2132
2124
0 commit comments