Skip to content

Commit 7caeb14

Browse files
jasnellrvagg
authored andcommitted
deps: update http-parser to 2.6.0
significant updates: * [[`777ba4eded`](777ba4eded)] - **src**: introduce `http_parser_url_init` (Fedor Indutny) [nodejs/http-parser#225](nodejs/http-parser#225) * [[`e557b62744`](e557b62744)] - **src**: support LINK/UNLINK (RFC 2068, draft-snell-link-method) (Olivier Mengué) [nodejs/http-parser#267](nodejs/http-parser#267) * [[`eb5e9928b4`](eb5e9928b4)] - **src**: support ACL (WebDAV, RFC3744, Section 8.1). (Ivan Enderlin) [nodejs/http-parser#260](nodejs/http-parser#260) * [[`8b1d652322`](8b1d652322)] - **src**: support BIND/REBIND/UNBIND (WebDAV, RFC5842) (Ivan Enderlin) [nodejs/http-parser#242](nodejs/http-parser#242) * [[`7d75dd7325`](7d75dd7325)] - **src**: support IPv6 Zone ID as per RFC 6874 (Tatsuhiro Tsujikawa) [nodejs/http-parser#253](nodejs/http-parser#253) PR-URL: #3569 Reviewed-By: Brian White <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
1 parent 045e04e commit 7caeb14

File tree

7 files changed

+309
-49
lines changed

7 files changed

+309
-49
lines changed

deps/http_parser/AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ Romain Giraud <[email protected]>
6565
Jay Satiro <[email protected]>
6666
Arne Steen <[email protected]>
6767
Kjell Schubert <[email protected]>
68+
Olivier Mengué <[email protected]>

deps/http_parser/Makefile

+22-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@
1919
# IN THE SOFTWARE.
2020

2121
PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
22-
SONAME ?= libhttp_parser.so.2.5.0
22+
HELPER ?=
23+
BINEXT ?=
24+
ifeq (darwin,$(PLATFORM))
25+
SONAME ?= libhttp_parser.2.6.0.dylib
26+
SOEXT ?= dylib
27+
else ifeq (wine,$(PLATFORM))
28+
CC = winegcc
29+
BINEXT = .exe.so
30+
HELPER = wine
31+
else
32+
SONAME ?= libhttp_parser.so.2.6.0
33+
SOEXT ?= so
34+
endif
2335

2436
CC?=gcc
2537
AR?=ar
@@ -53,8 +65,8 @@ LDFLAGS_LIB += -Wl,-soname=$(SONAME)
5365
endif
5466

5567
test: test_g test_fast
56-
./test_g
57-
./test_fast
68+
$(HELPER) ./test_g$(BINEXT)
69+
$(HELPER) ./test_fast$(BINEXT)
5870

5971
test_g: http_parser_g.o test_g.o
6072
$(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
@@ -81,7 +93,7 @@ http_parser.o: http_parser.c http_parser.h Makefile
8193
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
8294

8395
test-run-timed: test_fast
84-
while(true) do time ./test_fast > /dev/null; done
96+
while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done
8597

8698
test-valgrind: test_g
8799
valgrind ./test_g
@@ -102,23 +114,23 @@ url_parser_g: http_parser_g.o contrib/url_parser.c
102114
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
103115

104116
parsertrace: http_parser.o contrib/parsertrace.c
105-
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace
117+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT)
106118

107119
parsertrace_g: http_parser_g.o contrib/parsertrace.c
108-
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g
120+
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT)
109121

110122
tags: http_parser.c http_parser.h test.c
111123
ctags $^
112124

113125
install: library
114126
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
115127
$(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME)
116-
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
128+
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.$(SOEXT)
117129

118130
install-strip: library
119131
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
120132
$(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME)
121-
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
133+
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.$(SOEXT)
122134

123135
uninstall:
124136
rm $(INCLUDEDIR)/http_parser.h
@@ -128,7 +140,8 @@ uninstall:
128140
clean:
129141
rm -f *.o *.a tags test test_fast test_g \
130142
http_parser.tar libhttp_parser.so.* \
131-
url_parser url_parser_g parsertrace parsertrace_g
143+
url_parser url_parser_g parsertrace parsertrace_g \
144+
*.exe *.exe.so
132145

133146
contrib/url_parser.c: http_parser.h
134147
contrib/parsertrace.c: http_parser.h

deps/http_parser/README.md

+66-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ The Special Problem of Upgrade
9494
------------------------------
9595

9696
HTTP supports upgrading the connection to a different protocol. An
97-
increasingly common example of this is the Web Socket protocol which sends
97+
increasingly common example of this is the WebSocket protocol which sends
9898
a request like
9999

100100
GET /demo HTTP/1.1
@@ -106,8 +106,8 @@ a request like
106106

107107
followed by non-HTTP data.
108108

109-
(See http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 for more
110-
information the Web Socket protocol.)
109+
(See [RFC6455](https://tools.ietf.org/html/rfc6455) for more information the
110+
WebSocket protocol.)
111111

112112
To support this, the parser will treat this as a normal HTTP message without a
113113
body, issuing both on_headers_complete and on_message_complete callbacks. However
@@ -137,6 +137,69 @@ There are two types of callbacks:
137137
Callbacks must return 0 on success. Returning a non-zero value indicates
138138
error to the parser, making it exit immediately.
139139

140+
For cases where it is necessary to pass local information to/from a callback,
141+
the `http_parser` object's `data` field can be used.
142+
An example of such a case is when using threads to handle a socket connection,
143+
parse a request, and then give a response over that socket. By instantiation
144+
of a thread-local struct containing relevant data (e.g. accepted socket,
145+
allocated memory for callbacks to write into, etc), a parser's callbacks are
146+
able to communicate data between the scope of the thread and the scope of the
147+
callback in a threadsafe manner. This allows http-parser to be used in
148+
multi-threaded contexts.
149+
150+
Example:
151+
```
152+
typedef struct {
153+
socket_t sock;
154+
void* buffer;
155+
int buf_len;
156+
} custom_data_t;
157+
158+
159+
int my_url_callback(http_parser* parser, const char *at, size_t length) {
160+
/* access to thread local custom_data_t struct.
161+
Use this access save parsed data for later use into thread local
162+
buffer, or communicate over socket
163+
*/
164+
parser->data;
165+
...
166+
return 0;
167+
}
168+
169+
...
170+
171+
void http_parser_thread(socket_t sock) {
172+
int nparsed = 0;
173+
/* allocate memory for user data */
174+
custom_data_t *my_data = malloc(sizeof(custom_data_t));
175+
176+
/* some information for use by callbacks.
177+
* achieves thread -> callback information flow */
178+
my_data->sock = sock;
179+
180+
/* instantiate a thread-local parser */
181+
http_parser *parser = malloc(sizeof(http_parser));
182+
http_parser_init(parser, HTTP_REQUEST); /* initialise parser */
183+
/* this custom data reference is accessible through the reference to the
184+
parser supplied to callback functions */
185+
parser->data = my_data;
186+
187+
http_parser_settings settings; / * set up callbacks */
188+
settings.on_url = my_url_callback;
189+
190+
/* execute parser */
191+
nparsed = http_parser_execute(parser, &settings, buf, recved);
192+
193+
...
194+
/* parsed information copied from callback.
195+
can now perform action on data copied into thread-local memory from callbacks.
196+
achieves callback -> thread information flow */
197+
my_data->buffer;
198+
...
199+
}
200+
201+
```
202+
140203
In case you parse HTTP message in chunks (i.e. `read()` request line
141204
from socket, parse, read half headers, parse, etc) your data callbacks
142205
may be called more than once. Http-parser guarantees that data pointer is only

deps/http_parser/contrib/url_parser.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int main(int argc, char ** argv) {
3535
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
3636
printf("Parsing %s, connect %d\n", argv[2], connect);
3737

38+
http_parser_url_init(&u);
3839
result = http_parser_parse_url(argv[2], len, connect, &u);
3940
if (result != 0) {
4041
printf("Parse error : %d\n", result);
@@ -43,4 +44,4 @@ int main(int argc, char ** argv) {
4344
printf("Parse ok, result : \n");
4445
dump_url(argv[2], &u);
4546
return 0;
46-
}
47+
}

0 commit comments

Comments
 (0)