Skip to content

Commit b3a7da1

Browse files
committed
deps: update http_parser to 2.5.0
PR-URL: #1517 Reviewed-By: Brian White <[email protected]>
1 parent 5404cbc commit b3a7da1

14 files changed

+914
-302
lines changed

deps/http_parser/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tags
55
test
66
test_g
77
test_fast
8+
bench
89
url_parser
910
parsertrace
1011
parsertrace_g

deps/http_parser/.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Salman Haq <[email protected]>
55
Simon Zimmermann <[email protected]>
66
Thomas LE ROUX <[email protected]> LE ROUX Thomas <[email protected]>
77
Thomas LE ROUX <[email protected]> Thomas LE ROUX <[email protected]>
8+
Fedor Indutny <[email protected]>

deps/http_parser/.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ script:
1010
notifications:
1111
email: false
1212
irc:
13-
- "irc.freenode.net#libuv"
13+
- "irc.freenode.net#node-ci"

deps/http_parser/AUTHORS

+18-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,29 @@ BogDan Vatra <[email protected]>
3939
Peter Faiman <[email protected]>
4040
Corey Richardson <[email protected]>
4141
Tóth Tamás <[email protected]>
42-
Patrik Stutz <[email protected]>
4342
Cam Swords <[email protected]>
4443
Chris Dickinson <[email protected]>
4544
Uli Köhler <[email protected]>
4645
Charlie Somerville <[email protected]>
46+
Patrik Stutz <[email protected]>
4747
Fedor Indutny <[email protected]>
4848
4949
Alexis Campailla <[email protected]>
5050
David Wragg <[email protected]>
51+
Vinnie Falco <[email protected]>
52+
Alex Butum <[email protected]>
53+
54+
Alex Kocharin <[email protected]>
55+
Mark Koopman <[email protected]>
56+
Helge Heß <[email protected]>
57+
Alexis La Goutte <[email protected]>
58+
George Miroshnykov <[email protected]>
59+
Maciej Małecki <[email protected]>
60+
Marc O'Morain <[email protected]>
61+
Jeff Pinner <[email protected]>
62+
Timothy J Fontaine <[email protected]>
63+
64+
Romain Giraud <[email protected]>
65+
Jay Satiro <[email protected]>
66+
Arne Steen <[email protected]>
67+
Kjell Schubert <[email protected]>

deps/http_parser/CONTRIBUTIONS

-4
This file was deleted.

deps/http_parser/Makefile

+33-2
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,34 @@
1919
# IN THE SOFTWARE.
2020

2121
PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
22-
SONAME ?= libhttp_parser.so.2.3
22+
SONAME ?= libhttp_parser.so.2.5.0
2323

2424
CC?=gcc
2525
AR?=ar
2626

27+
CPPFLAGS ?=
28+
LDFLAGS ?=
29+
2730
CPPFLAGS += -I.
2831
CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
2932
CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
3033
CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
3134
CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
35+
CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
3236

3337
CFLAGS += -Wall -Wextra -Werror
3438
CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
3539
CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
40+
CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
3641
CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
3742

3843
LDFLAGS_LIB = $(LDFLAGS) -shared
3944

45+
INSTALL ?= install
46+
PREFIX ?= $(DESTDIR)/usr/local
47+
LIBDIR = $(PREFIX)/lib
48+
INCLUDEDIR = $(PREFIX)/include
49+
4050
ifneq (darwin,$(PLATFORM))
4151
# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
4252
LDFLAGS_LIB += -Wl,-soname=$(SONAME)
@@ -61,6 +71,12 @@ test_fast: http_parser.o test.o http_parser.h
6171
test.o: test.c http_parser.h Makefile
6272
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
6373

74+
bench: http_parser.o bench.o
75+
$(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
76+
77+
bench.o: bench.c http_parser.h Makefile
78+
$(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
79+
6480
http_parser.o: http_parser.c http_parser.h Makefile
6581
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
6682

@@ -94,6 +110,21 @@ parsertrace_g: http_parser_g.o contrib/parsertrace.c
94110
tags: http_parser.c http_parser.h test.c
95111
ctags $^
96112

113+
install: library
114+
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
115+
$(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME)
116+
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
117+
118+
install-strip: library
119+
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
120+
$(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME)
121+
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
122+
123+
uninstall:
124+
rm $(INCLUDEDIR)/http_parser.h
125+
rm $(LIBDIR)/$(SONAME)
126+
rm $(LIBDIR)/libhttp_parser.so
127+
97128
clean:
98129
rm -f *.o *.a tags test test_fast test_g \
99130
http_parser.tar libhttp_parser.so.* \
@@ -102,4 +133,4 @@ clean:
102133
contrib/url_parser.c: http_parser.h
103134
contrib/parsertrace.c: http_parser.h
104135

105-
.PHONY: clean package test-run test-run-timed test-valgrind
136+
.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall

deps/http_parser/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (recved < 0) {
6161
}
6262
6363
/* Start up / continue the parser.
64-
* Note we pass recved==0 to signal that EOF has been recieved.
64+
* Note we pass recved==0 to signal that EOF has been received.
6565
*/
6666
nparsed = http_parser_execute(parser, &settings, buf, recved);
6767
@@ -75,7 +75,7 @@ if (parser->upgrade) {
7575
HTTP needs to know where the end of the stream is. For example, sometimes
7676
servers send responses without Content-Length and expect the client to
7777
consume input (for the body) until EOF. To tell http_parser about EOF, give
78-
`0` as the forth parameter to `http_parser_execute()`. Callbacks and errors
78+
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
7979
can still be encountered during an EOF, so one must still be prepared
8080
to receive them.
8181

@@ -110,7 +110,7 @@ followed by non-HTTP data.
110110
information the Web Socket protocol.)
111111

112112
To support this, the parser will treat this as a normal HTTP message without a
113-
body. Issuing both on_headers_complete and on_message_complete callbacks. However
113+
body, issuing both on_headers_complete and on_message_complete callbacks. However
114114
http_parser_execute() will stop parsing at the end of the headers and return.
115115

116116
The user is expected to check if `parser->upgrade` has been set to 1 after
@@ -131,7 +131,7 @@ There are two types of callbacks:
131131
* notification `typedef int (*http_cb) (http_parser*);`
132132
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
133133
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
134-
Callbacks: (requests only) on_uri,
134+
Callbacks: (requests only) on_url,
135135
(common) on_header_field, on_header_value, on_body;
136136

137137
Callbacks must return 0 on success. Returning a non-zero value indicates
@@ -145,7 +145,7 @@ buffer to avoid copying memory around if this fits your application.
145145

146146
Reading headers may be a tricky task if you read/parse headers partially.
147147
Basically, you need to remember whether last header callback was field or value
148-
and apply following logic:
148+
and apply the following logic:
149149

150150
(on_header_field and on_header_value shortened to on_h_*)
151151
------------------------ ------------ --------------------------------------------

deps/http_parser/bench.c

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/* Copyright Fedor Indutny. All rights reserved.
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to
5+
* deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
* sell copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
* IN THE SOFTWARE.
20+
*/
21+
#include "http_parser.h"
22+
#include <assert.h>
23+
#include <stdio.h>
24+
#include <string.h>
25+
#include <sys/time.h>
26+
27+
static const char data[] =
28+
"POST /joyent/http-parser HTTP/1.1\r\n"
29+
"Host: github.com\r\n"
30+
"DNT: 1\r\n"
31+
"Accept-Encoding: gzip, deflate, sdch\r\n"
32+
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
33+
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) "
34+
"AppleWebKit/537.36 (KHTML, like Gecko) "
35+
"Chrome/39.0.2171.65 Safari/537.36\r\n"
36+
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,"
37+
"image/webp,*/*;q=0.8\r\n"
38+
"Referer: https://github.com/joyent/http-parser\r\n"
39+
"Connection: keep-alive\r\n"
40+
"Transfer-Encoding: chunked\r\n"
41+
"Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n";
42+
static const size_t data_len = sizeof(data) - 1;
43+
44+
static int on_info(http_parser* p) {
45+
return 0;
46+
}
47+
48+
49+
static int on_data(http_parser* p, const char *at, size_t length) {
50+
return 0;
51+
}
52+
53+
static http_parser_settings settings = {
54+
.on_message_begin = on_info,
55+
.on_headers_complete = on_info,
56+
.on_message_complete = on_info,
57+
.on_header_field = on_data,
58+
.on_header_value = on_data,
59+
.on_url = on_data,
60+
.on_status = on_data,
61+
.on_body = on_data
62+
};
63+
64+
int bench(int iter_count, int silent) {
65+
struct http_parser parser;
66+
int i;
67+
int err;
68+
struct timeval start;
69+
struct timeval end;
70+
float rps;
71+
72+
if (!silent) {
73+
err = gettimeofday(&start, NULL);
74+
assert(err == 0);
75+
}
76+
77+
for (i = 0; i < iter_count; i++) {
78+
size_t parsed;
79+
http_parser_init(&parser, HTTP_REQUEST);
80+
81+
parsed = http_parser_execute(&parser, &settings, data, data_len);
82+
assert(parsed == data_len);
83+
}
84+
85+
if (!silent) {
86+
err = gettimeofday(&end, NULL);
87+
assert(err == 0);
88+
89+
fprintf(stdout, "Benchmark result:\n");
90+
91+
rps = (float) (end.tv_sec - start.tv_sec) +
92+
(end.tv_usec - start.tv_usec) * 1e-6f;
93+
fprintf(stdout, "Took %f seconds to run\n", rps);
94+
95+
rps = (float) iter_count / rps;
96+
fprintf(stdout, "%f req/sec\n", rps);
97+
fflush(stdout);
98+
}
99+
100+
return 0;
101+
}
102+
103+
int main(int argc, char** argv) {
104+
if (argc == 2 && strcmp(argv[1], "infinite") == 0) {
105+
for (;;)
106+
bench(5000000, 1);
107+
return 0;
108+
} else {
109+
return bench(5000000, 0);
110+
}
111+
}

deps/http_parser/contrib/parsertrace.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ int main(int argc, char* argv[]) {
111111
FILE* file = fopen(filename, "r");
112112
if (file == NULL) {
113113
perror("fopen");
114-
return EXIT_FAILURE;
114+
goto fail;
115115
}
116116

117117
fseek(file, 0, SEEK_END);
118118
long file_length = ftell(file);
119119
if (file_length == -1) {
120120
perror("ftell");
121-
return EXIT_FAILURE;
121+
goto fail;
122122
}
123123
fseek(file, 0, SEEK_SET);
124124

125125
char* data = malloc(file_length);
126126
if (fread(data, 1, file_length, file) != (size_t)file_length) {
127127
fprintf(stderr, "couldn't read entire file\n");
128128
free(data);
129-
return EXIT_FAILURE;
129+
goto fail;
130130
}
131131

132132
http_parser_settings settings;
@@ -149,8 +149,12 @@ int main(int argc, char* argv[]) {
149149
"Error: %s (%s)\n",
150150
http_errno_description(HTTP_PARSER_ERRNO(&parser)),
151151
http_errno_name(HTTP_PARSER_ERRNO(&parser)));
152-
return EXIT_FAILURE;
152+
goto fail;
153153
}
154154

155155
return EXIT_SUCCESS;
156+
157+
fail:
158+
fclose(file);
159+
return EXIT_FAILURE;
156160
}

deps/http_parser/contrib/url_parser.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dump_url (const char *url, const struct http_parser_url *u)
1414
continue;
1515
}
1616

17-
printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n",
17+
printf("\tfield_data[%u]: off: %u, len: %u, part: %.*s\n",
1818
i,
1919
u->field_data[i].off,
2020
u->field_data[i].len,
@@ -24,16 +24,18 @@ dump_url (const char *url, const struct http_parser_url *u)
2424
}
2525

2626
int main(int argc, char ** argv) {
27+
struct http_parser_url u;
28+
int len, connect, result;
29+
2730
if (argc != 3) {
2831
printf("Syntax : %s connect|get url\n", argv[0]);
2932
return 1;
3033
}
31-
struct http_parser_url u;
32-
int len = strlen(argv[2]);
33-
int connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
34+
len = strlen(argv[2]);
35+
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
3436
printf("Parsing %s, connect %d\n", argv[2], connect);
3537

36-
int result = http_parser_parse_url(argv[2], len, connect, &u);
38+
result = http_parser_parse_url(argv[2], len, connect, &u);
3739
if (result != 0) {
3840
printf("Parse error : %d\n", result);
3941
return result;

0 commit comments

Comments
 (0)