Skip to content

Commit b893859

Browse files
committed
Upgrade http parser, change node as needed.
The latest version of http-parser is a bit more stringent EOF semantics.
1 parent 3456a16 commit b893859

13 files changed

+3176
-2998
lines changed

deps/http_parser/LICENSE

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Copyright 2009, Ryan Lienhart Dahl. All rights reserved.
2+
23
Permission is hereby granted, free of charge, to any person obtaining a copy
34
of this software and associated documentation files (the "Software"), to
45
deal in the Software without restriction, including without limitation the
@@ -15,16 +16,13 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1516
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1617
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1718
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18-
IN THE SOFTWARE.
19-
20-
21-
19+
IN THE SOFTWARE.
2220

2321
http_parser is based on Zed Shaw's Mongrel. Mongrel's license is as follows.
2422

25-
-- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT --
23+
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----
2624
Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
27-
<zedshaw at zedshaw dot com> and contributors. You can redistribute it
25+
<zedshaw at zedshaw dot com> and contributors. You can redistribute it
2826
and/or modify it under either the terms of the GPL2 or the conditions below:
2927

3028
1. You may make and give away verbatim copies of the source form of the
@@ -66,14 +64,14 @@ and/or modify it under either the terms of the GPL2 or the conditions below:
6664
software (possibly commercial). But some files in the distribution
6765
are not written by the author, so that they are not under this terms.
6866

69-
5. The scripts and library files supplied as input to or produced as
67+
5. The scripts and library files supplied as input to or produced as
7068
output from the software do not automatically fall under the
71-
copyright of the software, but belong to whomever generated them,
69+
copyright of the software, but belong to whomever generated them,
7270
and may be sold commercially, and may be aggregated with this
7371
software.
7472

7573
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
7674
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
7775
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
7876
PURPOSE.
79-
-- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT ---- CUT --
77+
---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ---- 8< ----

deps/http_parser/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#OPT=-O0 -g -Wall -Wextra -Werror
22
OPT=-O2
33

4-
test: http_parser.o test.c
5-
gcc $(OPT) http_parser.o test.c -o $@
4+
test: http_parser.o test.c
5+
gcc $(OPT) http_parser.o test.c -o $@
66

77
http_parser.o: http_parser.c http_parser.h Makefile
88
gcc $(OPT) -c http_parser.c

deps/http_parser/README.md

+27-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ This is a parser for HTTP messages written in C. It parses both requests
55
and responses. The parser is designed to be used in performance HTTP
66
applications. It does not make any allocations, it does not buffer data, and
77
it can be interrupted at anytime. It only requires about 128 bytes of data
8-
per message stream (in a web server that is per connection).
8+
per message stream (in a web server that is per connection).
99

1010
Features:
1111

12-
* No dependencies
12+
* No dependencies
1313
* Parses both requests and responses.
1414
* Handles keep-alive streams.
1515
* Decodes chunked encoding.
@@ -43,21 +43,35 @@ When data is received on the socket execute the parser and check for errors.
4343
char buf[len];
4444
ssize_t recved;
4545

46-
recved = read(fd, buf, len);
47-
if (recved != 0) // handle error
46+
recved = recv(fd, buf, len, 0);
4847

48+
if (recved < 0) {
49+
/* Handle error. */
50+
}
51+
52+
/* Start up / continue the parser.
53+
* Note we pass the recved==0 to http_parser_execute to signal
54+
* that EOF has been recieved.
55+
*/
4956
http_parser_execute(parser, buf, recved);
5057

5158
if (http_parser_has_error(parser)) {
52-
// handle error. usually just close the connection
59+
/* Handle error. Usually just close the connection. */
5360
}
5461

62+
HTTP needs to know where the end of the stream is. For example, sometimes
63+
servers send responses without Content-Length and expect the client to
64+
consume input (for the body) until EOF. To tell http_parser about EOF, give
65+
`0` as the third parameter to `http_parser_execute()`. Callbacks and errors
66+
can still be encountered during an EOF, so one must still be prepared
67+
to receive them.
68+
5569
Scalar valued message information such as `status_code`, `method`, and the
5670
HTTP version are stored in the parser structure. This data is only
5771
temporarlly stored in `http_parser` and gets reset on each new message. If
5872
this information is needed later, copy it out of the structure during the
5973
`headers_complete` callback.
60-
74+
6175
The parser decodes the transfer-encoding for both requests and responses
6276
transparently. That is, a chunked encoding is decoded before being sent to
6377
the on_body callback.
@@ -129,3 +143,10 @@ Releases
129143
* [0.1](http://s3.amazonaws.com/four.livejournal/20090427/http_parser-0.1.tar.gz)
130144

131145
The source repo is at [github](http://github.com/ry/http-parser).
146+
147+
Bindings
148+
--------
149+
150+
* [Ruby](http://github.com/yakischloba/http-parser-ffi)
151+
152+
* [Lua](http://github.com/phoenixsol/lua-http-parser)

0 commit comments

Comments
 (0)