Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7dd451

Browse filesBrowse files
indutnyMylesBorins
authored andcommitted
deps: update to http-parser 2.7.0
Adds `2` as a return value of `on_headers_complete`, this mode will be used to fix handling responses to `CONNECT` requests. See: #6198 PR-URL: #6279 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9f2dc70 commit b7dd451
Copy full SHA for b7dd451

File tree

Expand file treeCollapse file tree

4 files changed

+98
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+98
-21
lines changed
Open diff view settings
Collapse file

‎deps/http_parser/Makefile‎

Copy file name to clipboardExpand all lines: deps/http_parser/Makefile
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
2222
HELPER ?=
2323
BINEXT ?=
2424
ifeq (darwin,$(PLATFORM))
25-
SONAME ?= libhttp_parser.2.6.2.dylib
25+
SONAME ?= libhttp_parser.2.7.0.dylib
2626
SOEXT ?= dylib
2727
else ifeq (wine,$(PLATFORM))
2828
CC = winegcc
2929
BINEXT = .exe.so
3030
HELPER = wine
3131
else
32-
SONAME ?= libhttp_parser.so.2.6.2
32+
SONAME ?= libhttp_parser.so.2.7.0
3333
SOEXT ?= so
3434
endif
3535

Collapse file

‎deps/http_parser/http_parser.c‎

Copy file name to clipboardExpand all lines: deps/http_parser/http_parser.c
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,9 @@ size_t http_parser_execute (http_parser *parser,
18121812
case 0:
18131813
break;
18141814

1815+
case 2:
1816+
parser->upgrade = 1;
1817+
18151818
case 1:
18161819
parser->flags |= F_SKIPBODY;
18171820
break;
Collapse file

‎deps/http_parser/http_parser.h‎

Copy file name to clipboardExpand all lines: deps/http_parser/http_parser.h
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extern "C" {
2626

2727
/* Also update SONAME in the Makefile whenever you change these. */
2828
#define HTTP_PARSER_VERSION_MAJOR 2
29-
#define HTTP_PARSER_VERSION_MINOR 6
30-
#define HTTP_PARSER_VERSION_PATCH 2
29+
#define HTTP_PARSER_VERSION_MINOR 7
30+
#define HTTP_PARSER_VERSION_PATCH 0
3131

3232
#include <sys/types.h>
3333
#if defined(_WIN32) && !defined(__MINGW32__) && \
@@ -77,6 +77,11 @@ typedef struct http_parser_settings http_parser_settings;
7777
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
7878
* chunked' headers that indicate the presence of a body.
7979
*
80+
* Returning `2` from on_headers_complete will tell parser that it should not
81+
* expect neither a body nor any futher responses on this connection. This is
82+
* useful for handling responses to a CONNECT request which may not contain
83+
* `Upgrade` or `Connection: upgrade` headers.
84+
*
8085
* http_data_cb does not return data chunks. It will be called arbitrarily
8186
* many times for each string. E.G. you might get 10 callbacks for "on_url"
8287
* each providing just a few characters more data.
Collapse file

‎deps/http_parser/test.c‎

Copy file name to clipboardExpand all lines: deps/http_parser/test.c
+86-17Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,20 @@ pause_chunk_complete_cb (http_parser *p)
21732173
return chunk_complete_cb(p);
21742174
}
21752175

2176+
int
2177+
connect_headers_complete_cb (http_parser *p)
2178+
{
2179+
headers_complete_cb(p);
2180+
return 1;
2181+
}
2182+
2183+
int
2184+
connect_message_complete_cb (http_parser *p)
2185+
{
2186+
messages[num_messages].should_keep_alive = http_should_keep_alive(parser);
2187+
return message_complete_cb(p);
2188+
}
2189+
21762190
static http_parser_settings settings_pause =
21772191
{.on_message_begin = pause_message_begin_cb
21782192
,.on_header_field = pause_header_field_cb
@@ -2212,6 +2226,19 @@ static http_parser_settings settings_count_body =
22122226
,.on_chunk_complete = chunk_complete_cb
22132227
};
22142228

2229+
static http_parser_settings settings_connect =
2230+
{.on_message_begin = message_begin_cb
2231+
,.on_header_field = header_field_cb
2232+
,.on_header_value = header_value_cb
2233+
,.on_url = request_url_cb
2234+
,.on_status = response_status_cb
2235+
,.on_body = dontcall_body_cb
2236+
,.on_headers_complete = connect_headers_complete_cb
2237+
,.on_message_complete = connect_message_complete_cb
2238+
,.on_chunk_header = chunk_header_cb
2239+
,.on_chunk_complete = chunk_complete_cb
2240+
};
2241+
22152242
static http_parser_settings settings_null =
22162243
{.on_message_begin = 0
22172244
,.on_header_field = 0
@@ -2275,6 +2302,14 @@ size_t parse_pause (const char *buf, size_t len)
22752302
return nparsed;
22762303
}
22772304

2305+
size_t parse_connect (const char *buf, size_t len)
2306+
{
2307+
size_t nparsed;
2308+
currently_parsing_eof = (len == 0);
2309+
nparsed = http_parser_execute(parser, &settings_connect, buf, len);
2310+
return nparsed;
2311+
}
2312+
22782313
static inline int
22792314
check_str_eq (const struct message *m,
22802315
const char *prop,
@@ -2331,7 +2366,7 @@ do { \
23312366
} while(0)
23322367

23332368
int
2334-
message_eq (int index, const struct message *expected)
2369+
message_eq (int index, int connect, const struct message *expected)
23352370
{
23362371
int i;
23372372
struct message *m = &messages[index];
@@ -2346,8 +2381,10 @@ message_eq (int index, const struct message *expected)
23462381
MESSAGE_CHECK_STR_EQ(expected, m, response_status);
23472382
}
23482383

2349-
MESSAGE_CHECK_NUM_EQ(expected, m, should_keep_alive);
2350-
MESSAGE_CHECK_NUM_EQ(expected, m, message_complete_on_eof);
2384+
if (!connect) {
2385+
MESSAGE_CHECK_NUM_EQ(expected, m, should_keep_alive);
2386+
MESSAGE_CHECK_NUM_EQ(expected, m, message_complete_on_eof);
2387+
}
23512388

23522389
assert(m->message_begin_cb_called);
23532390
assert(m->headers_complete_cb_called);
@@ -2385,16 +2422,22 @@ message_eq (int index, const struct message *expected)
23852422
MESSAGE_CHECK_NUM_EQ(expected, m, port);
23862423
}
23872424

2388-
if (expected->body_size) {
2425+
if (connect) {
2426+
check_num_eq(m, "body_size", 0, m->body_size);
2427+
} else if (expected->body_size) {
23892428
MESSAGE_CHECK_NUM_EQ(expected, m, body_size);
23902429
} else {
23912430
MESSAGE_CHECK_STR_EQ(expected, m, body);
23922431
}
23932432

2394-
assert(m->num_chunks == m->num_chunks_complete);
2395-
MESSAGE_CHECK_NUM_EQ(expected, m, num_chunks_complete);
2396-
for (i = 0; i < m->num_chunks && i < MAX_CHUNKS; i++) {
2397-
MESSAGE_CHECK_NUM_EQ(expected, m, chunk_lengths[i]);
2433+
if (connect) {
2434+
check_num_eq(m, "num_chunks_complete", 0, m->num_chunks_complete);
2435+
} else {
2436+
assert(m->num_chunks == m->num_chunks_complete);
2437+
MESSAGE_CHECK_NUM_EQ(expected, m, num_chunks_complete);
2438+
for (i = 0; i < m->num_chunks && i < MAX_CHUNKS; i++) {
2439+
MESSAGE_CHECK_NUM_EQ(expected, m, chunk_lengths[i]);
2440+
}
23982441
}
23992442

24002443
MESSAGE_CHECK_NUM_EQ(expected, m, num_headers);
@@ -3201,7 +3244,7 @@ test_message (const struct message *message)
32013244
abort();
32023245
}
32033246

3204-
if(!message_eq(0, message)) abort();
3247+
if(!message_eq(0, 0, message)) abort();
32053248

32063249
parser_free();
32073250
}
@@ -3238,7 +3281,7 @@ test_message_count_body (const struct message *message)
32383281
abort();
32393282
}
32403283

3241-
if(!message_eq(0, message)) abort();
3284+
if(!message_eq(0, 0, message)) abort();
32423285

32433286
parser_free();
32443287
}
@@ -3589,9 +3632,9 @@ test_multiple3 (const struct message *r1, const struct message *r2, const struct
35893632
abort();
35903633
}
35913634

3592-
if (!message_eq(0, r1)) abort();
3593-
if (message_count > 1 && !message_eq(1, r2)) abort();
3594-
if (message_count > 2 && !message_eq(2, r3)) abort();
3635+
if (!message_eq(0, 0, r1)) abort();
3636+
if (message_count > 1 && !message_eq(1, 0, r2)) abort();
3637+
if (message_count > 2 && !message_eq(2, 0, r3)) abort();
35953638

35963639
parser_free();
35973640
}
@@ -3687,17 +3730,17 @@ test_scan (const struct message *r1, const struct message *r2, const struct mess
36873730
goto error;
36883731
}
36893732

3690-
if (!message_eq(0, r1)) {
3733+
if (!message_eq(0, 0, r1)) {
36913734
fprintf(stderr, "\n\nError matching messages[0] in test_scan.\n");
36923735
goto error;
36933736
}
36943737

3695-
if (message_count > 1 && !message_eq(1, r2)) {
3738+
if (message_count > 1 && !message_eq(1, 0, r2)) {
36963739
fprintf(stderr, "\n\nError matching messages[1] in test_scan.\n");
36973740
goto error;
36983741
}
36993742

3700-
if (message_count > 2 && !message_eq(2, r3)) {
3743+
if (message_count > 2 && !message_eq(2, 0, r3)) {
37013744
fprintf(stderr, "\n\nError matching messages[2] in test_scan.\n");
37023745
goto error;
37033746
}
@@ -3796,7 +3839,29 @@ test_message_pause (const struct message *msg)
37963839
abort();
37973840
}
37983841

3799-
if(!message_eq(0, msg)) abort();
3842+
if(!message_eq(0, 0, msg)) abort();
3843+
3844+
parser_free();
3845+
}
3846+
3847+
/* Verify that body and next message won't be parsed in responses to CONNECT */
3848+
void
3849+
test_message_connect (const struct message *msg)
3850+
{
3851+
char *buf = (char*) msg->raw;
3852+
size_t buflen = strlen(msg->raw);
3853+
size_t nread;
3854+
3855+
parser_init(msg->type);
3856+
3857+
nread = parse_connect(buf, buflen);
3858+
3859+
if (num_messages != 1) {
3860+
printf("\n*** num_messages != 1 after testing '%s' ***\n\n", msg->name);
3861+
abort();
3862+
}
3863+
3864+
if(!message_eq(0, 1, msg)) abort();
38003865

38013866
parser_free();
38023867
}
@@ -3867,6 +3932,10 @@ main (void)
38673932
test_message_pause(&responses[i]);
38683933
}
38693934

3935+
for (i = 0; i < response_count; i++) {
3936+
test_message_connect(&responses[i]);
3937+
}
3938+
38703939
for (i = 0; i < response_count; i++) {
38713940
if (!responses[i].should_keep_alive) continue;
38723941
for (j = 0; j < response_count; j++) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.