Commit Graph

146 Commits

Author SHA1 Message Date
Ryan Dahl
eee60127c0 Support PATCH method
Requested in https://groups.google.com/forum/#!topic/nodejs-dev/iEOyiDkJRLs
2011-06-03 14:08:57 +02:00
Peter Griess
3bd18a779e IS_* macros for char classes.
- Add IS_ALPHA(), IS_NUM(), IS_HOST_CHAR(), etc. macros for determining
  membership in a character class. HTTP_PARSER_STRICT causes some of
  these definitions to change.
- Support '_' character in hostnames in non-strict mode.
- Support leading digits in hostnames when the method is HTTP_CONNECT.
- Don't re-define HTTP_PARSER_STRICT in http_parser.h if it's already
  defined.
- Tweak Makefile to run non-strict-mode unit tests. Rearrange non-strict
  mode unit tests in test.c.
- Add test_fast to .gitignore.

Fixes #44
2011-05-27 22:26:40 -07:00
Ryan Dahl
2839784927 HTTP_STRICT ifdefs out behavior introduced in 50b9bec
Fixes #37.
2011-05-24 09:08:06 -07:00
Peter Griess
b1c2cf83fd Expose F_* flags as public API.
Fixes #42.
2011-05-24 08:57:13 -07:00
Ryan Dahl
8dabce6ec7 It was pointed out we're missing attribution to NGINX 2011-05-15 13:02:20 -07:00
Peter Griess
9639c7c21c Support ?-terminated hostnames per RFC 2396.3.2.
- Bust out of s_req_host and s_req_port on '?'.
- Add tests for query string parsing.

Fixes #38.
2011-05-11 11:52:35 -07:00
Peter Griess
50b9bec552 Allow octets > 127 in path components.
- This is non-spec behavior, but it appears that most HTTP servers
  implicitly support non-ASCII characters when parsing path components.
  Extend http-parser to allow this.
- Fill out slots [128, 256) in normal_url_char[] with 1 so that these
  high octets are accepted in path components.
- Add unit test for paths that include such non-ASCII characters.

Fixes #37.
2011-05-11 10:30:29 -07:00
Ryan Dahl
63daf22f2c Update copyright headers 2011-03-22 13:30:24 -07:00
Sean Cunningham
10270007bc Avoid chunk header parsing overflow.
Recharacterize the chunk header states such that they are bound by the check
for HTTP_MAX_HEADER_SIZE.
2011-02-25 09:52:32 -08:00
Sean Cunningham
81ca70aec1 Avoid chunk trailer overflow.
Check for overflow during chunk trailer by removing unnecessary check in macro PARSING_HEADER.  This will force the parser to abort if the chunk trailer contains more than HTTP_MAX_HEADER_SIZE of data.
2011-02-25 09:51:44 -08:00
Ryan Dahl
1c3624a963 Detect errors on EOF 2011-02-04 15:57:09 -08:00
Ryan Dahl
fcdbc2629f Add hack for tmm1 2011-01-25 20:32:23 -08:00
Tim Becker
9656fd73de moved unecessary lookup 2010-12-05 15:26:26 +01:00
Nathan Rajlich
f825b52b7f Added support for "SUBSCRIBE" and "UNSUBSCRIBE" request methods. 2010-11-21 21:37:57 -08:00
Nathan Rajlich
d56a0700d0 Add support for "M-SEARCH" and "NOTIFY" request methods.
Allow a request path of "*" (for SSDP requests).
2010-11-21 21:37:57 -08:00
Nathan Rajlich
84578ae7a8 Set http_major when a request omits the HTTP version
I.E. "GET /" in telnet
2010-11-10 22:04:35 -08:00
Ryan Dahl
37e9009369 Digits in hostname on CONNECT req allowed 2010-11-10 21:42:00 -08:00
Cliff Frey
90320fde7a Remove acceptable_header array
This was not necessary, as it was just being used as a downcase
function.
2010-11-10 21:34:51 -08:00
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