Commit Graph

78 Commits

Author SHA1 Message Date
Ryan Dahl
51de89f8b0 Accept tokens + SP for header fields 2010-11-05 15:25:54 -07:00
Ewen Cheslack-Postava
24be793f64 Provide typedefs instead of using stdint.h on Windows. 2010-11-04 20:36:14 -07:00
Nathan Rajlich
a66c61c190 Allow whitespace in the 'Content-Length' header. 2010-10-12 09:29:10 -07:00
Cliff Frey
459507f534 avoid assertion failure in error case
Without this change, it is possible to get an assertion to fail by
continuing to call http_parser_execute after it has returned an error.
Specifically, the parser could be called with parser->state ==
s_chunk_size_almost_done and parser->flags & F_CHUNKED set.  Then,
F_CHUNKED could have been cleared, and an error could be hit.  In this
case, the parser would have returned with F_CHUNKED clear, but
parser->state == s_chunk_size_almost_done, resulting in an assertion
failure on the next call.

There are alternate solutions possible, including just saving all of
the fields (state included) on error.

I didn't add a test case because this is a bit annoying to test, but I
can add one if necesssary.
2010-09-11 18:32:43 -07:00
Ben Noordhuis
cbb194ea8c Replace C++ style comments with C comments so it compiles with gcc -ansi -Wall 2010-08-27 05:36:16 -07:00
Cliff Frey
ca2514dd3a Array type cleanups. Also save space
acceptable_header[x] is always assigned to a variable of type char, so
the 'unsigned' is unnecessary.

The other arrays can be of type int8_t/uint8_t to save space.
2010-08-18 11:06:51 -07:00
Cliff Frey
423c90d9fe fixes for architectures with signed char default
This could have resulted in memory before the normal_url_char array
being read on architectures with signed char default.
2010-08-18 11:06:47 -07:00
Ryan Dahl
6f12467a8a Use lookup tables of my own. 2010-07-31 14:27:58 -07:00
Jeff Terrace
d0dfc98773 Initialize method member to avoid falsely upgrading connections. Fixed Issue #7 2010-07-30 11:06:31 -07:00
Ryan Dahl
a59ba4d866 Support long messages 2010-07-26 14:59:39 -07:00
Ryan Dahl
120f0f6e09 Allow spaces in header fields 2010-07-24 16:37:27 -07:00
Ryan Dahl
5f27ea8179 Fix long line 2010-07-24 16:27:32 -07:00
Tim Becker
8c3101cbe2 redundant upgrade flag check 2010-07-18 22:50:19 -07:00
Santiago Gala
0264a0aefc Upgrade on CONNECT method 2010-07-17 01:20:48 -07:00
Cliff Frey
deaee07c86 fix http_parser_init to initialize flags correctly
Yay valgrind testing

I don't believe that this actually mattered at all, because state was
initialized correctly, and flags would be set to 0 almost immediately
anyways.
2010-07-07 00:41:39 +02:00
Ryan Dahl
c46b3e3942 Fix typo s_start_res_or_resp 2010-07-06 16:35:48 +02:00
Ryan Dahl
03b8eaa5f8 Reset url_mark on s_req_host
add a new scan test. Report and fix by Master Becker.
2010-07-06 12:00:52 +02:00
Ewen Cheslack-Postava
4afe80a44e Add definitions and typedefs to support compilation in Visual Studio under C++ mode. 2010-06-28 00:14:25 -07:00
Ryan Dahl
ddbd5c3728 Expose http_method_str() to get a string version of a method 2010-06-23 21:04:57 -07:00
Ryan Dahl
9dc258f9dd Add subversion request methods
REPORT, MKACTIVITY, CHECKOUT, MERGE
2010-06-23 21:04:32 -07:00
Cliff Frey
6533f8ac9c do not access random memory before lowcase array
This matters because char is signed by default on x86, so bytes with
values above 127 could have theoretically survived a pass through
lowcase (assuming that there was some non-zero data before the lowcase
array).
2010-06-11 17:28:58 -07:00
Cliff Frey
9eac636531 save more space by removing buffer and shortening method
This also fixes test failures from the previous commit.

It also adds support for the LOCK method, which was previously
missing.

This brings the size of http_parser from 44 bytes to 32 bytes.  It
also makes the code substantially shorter, at a slight cost in
craziness.
2010-06-11 15:17:38 -07:00
Cliff Frey
546f43a782 remove body_read
This saves space in the structure (it is now 28 bytes on x86), and
makes the handling of content_length more consistent between chunked
encoding and non-chunked-encoding.
2010-06-11 11:15:06 -07:00
Cliff Frey
2d16d50425 only increment nread while looking at headers
This fixes a possible issue where a very large body (one that involves
> 80*1024 calls to http_parser_execute) will cause the next request
with that parser to return an error because it believes that this is
an overflow condition.
2010-06-11 10:58:42 -07:00
Ryan Dahl
4cf39fd2fa Support request URLs without schema
Test case from Poul T Lomholt <pt@lomholt.com>
2010-06-06 16:18:41 -07:00
Ryan Dahl
cdda8b6a60 Support empty header values
Test case by Pierre Ruyssen <pierre@ruyssen.fr>
2010-06-06 16:01:42 -07:00
Cliff Frey
8732d108a4 stop tracking lengths of returned values
This drops support for MAX_FIELD_SIZE, and saves 4 more bytes in the
parser object (44 bytes total now).
2010-05-28 12:42:12 -07:00
Cliff Frey
076fa15132 reduce the size of the http_parser struct
The *_mark members were actually being used as just boolean values to
the next call of the parser.  However, you can calculate if the mark
members should be set or not purely based on the current state, so
they can just be gotten rid of entirely.
2010-05-28 12:41:27 -07:00
Cliff Frey
0e8ad4e003 reduce size of http_parser object from 104 to 84 bytes by only tracking one field size
This does have some slight functional changes in cases where
MAX_FIELD_SIZE is hit, specficially if a URL is made up of many
components, each of which is smaller than MAX_FIELD_SIZE, but the
total together is greater than MAX_FIELD_SIZE, then we now might not
call callbacks for any of the components (even the ones that are
smaller than 80kb).  With the old code, it was possible to get a
callback for query_string and never get a callback for the URL (or at
least the end of the URL that is past 80kb), if the callback for the
URL would have been larger than 80kb.

(to be honest, I'm surprised that the MAX_FIELD_SIZE is implemented in
http_parser at all, instead of requiring that callers pay attention to
it, as it feels like it should be the caller's responsibility)
2010-05-28 01:02:16 -07:00
Ryan Dahl
8beed7ef17 Fix whitespace 2010-05-27 11:48:13 -07:00
Cliff Frey
b8c3336f5d add support for HTTP_BOTH
This is good for analyzing raw streams of data when one is not sure
which direction it will be in.
2010-05-27 00:40:44 -07:00
Ryan Dahl
c2acc213ac Skip body for HEAD responses
TODO: need test for response with non-zero content length but no body.
2010-05-25 16:35:22 -07:00
Cliff Frey
7239788205 pass pointer to settings structure rather than pass by value 2010-05-11 12:12:23 -07:00
Ryan Dahl
7cfa645fc7 Fix long chunked message bug
The HTTP_MAX_HEADER_SIZE was being consulted at the end of the chunked
message (when you look for trailing headers).

http://github.com/ry/node/issues#issue/77
2010-04-28 23:21:49 -07:00
Ryan Dahl
88d11b394d Support Upgrade header 2010-04-14 03:17:11 -07:00
Ryan Dahl
da30924dc8 Use stddef.h 2010-03-10 19:52:42 -08:00
Ryan Dahl
a458431e38 Remove string.h include 2010-02-27 21:27:13 -08:00
Ryan Dahl
e07e0b952e Tasteful vertical whitespace. 2010-02-27 21:24:09 -08:00
Ryan Dahl
4bce6b4467 Use nginx-style method compare
If only just to remove dependency on strncmp().
2010-02-27 21:18:08 -08:00
Ryan Dahl
dbd2dad461 Introduce http_parser_settings 2010-02-27 20:31:05 -08:00
Ryan Dahl
ef14734f6c Use marcros instead of inline funcs to do callbacks
Simplifies things.
2010-02-27 20:14:34 -08:00
Ryan Dahl
8243fddd17 Fix c++ and mac compile errors 2010-02-20 17:10:22 -08:00
Ryan Dahl
1b30bf4ba5 Only allow 80kb of header bytes 2010-02-02 16:41:45 -08:00
Cliff Frey
d5a900264f Allow newlines before HTTP requests.
I have seen cases where a browser will POST data, and then send an
extra CRLF before issuing the next request.
2010-02-02 09:17:19 -08:00
Cliff Frey
f167565742 Allow '_' in header fields.
Technically anything defined as a 'token' by
http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2 should be
allowed, which includes !#$%^&*+-.`~| and probably others.  However
this is the only one that I have found in use.
2010-02-02 09:15:48 -08:00
Cliff Frey
6409a5bd17 Allow extra '?' in query strings, and add a test for it. 2010-02-02 09:14:39 -08:00
Cliff Frey
ae8234de93 Prevent uninitialized variable use 2010-02-02 09:14:15 -08:00
Ryan Dahl
9cbd66e49a Support 'Proxy-Connection' header
See http://www.http-stats.com/Proxy-Connection
2010-01-09 01:16:19 -08:00
Ryan Dahl
caef58793e Update license for 2010 2010-01-08 21:42:02 -08:00
Ryan Dahl
1a677040c0 API: Define parser type in http_parser_init()
That is, for a request parser do this:

  http_parser_init(my_parser, HTTP_REQUEST)

for a response parser do this:

  http_parser_init(my_parser, HTTP_RESPONSE)

Then http_parse_requests() and http_parse_responses() both turn
into http_parer_execute().
2010-01-08 21:38:17 -08:00