Commit Graph

114 Commits

Author SHA1 Message Date
koichik
b47c44d7a6 Fix response body is not read
With HTTP/1.1, if neither Content-Length nor Transfer-Encoding is present,
section 4.4 of RFC 2616 suggests http-parser needs to read a response body
until the connection is closed (except the response must not include a body)

See also joyent/node#2457.
Fixes #72
2012-01-05 22:17:12 -08:00
Felix Geisendörfer
2498961231 Accept HTTP/0.9 responses
See joyent/node#1711
2011-11-22 12:51:01 -08:00
Paul Querna
f1d48aa31c Move all data to before code to fix http parser for c89. 2011-10-02 00:36:16 -04:00
Fouad Mardini
2b2ba2da1a rename parser->errno to parser->http_errno; conflicts with errno.h where errno is defined as a macro 2011-07-24 18:49:54 +03:00
Peter Griess
53adfacad1 API CHANGE: Remove path, query, fragment CBs.
- Get rid of support for these callbacks in http_parser_settings.
- Retain state transitions between different URL portions in
  http_parser_execute() so that we're making the same correctness
  guarantees as before.
- These are being removed because making multiple callbacks for the same
  byte makes it more difficult to pause the parser.
2011-07-20 12:16:07 -05:00
Peter Griess
49faf2e9cd Merge pull request #53 from pgriess/callback_noclear
Get rid of CALLBACK_NOCLEAR().
2011-07-20 10:06:46 -07:00
Peter Griess
5469827542 Get rid of CALLBACK_NOCLEAR().
- This was only used by CALLBACK() (which then cleared the mark anyway),
  and the end of the http_parser_execute() body (after which they
  go out of scope).
2011-07-09 13:57:17 -05:00
Peter Griess
761a5eaeb1 Break out errno into its own field. 2011-07-09 11:51:13 -05:00
Jon Kolb
8153466643 Group POST refinements, test all request methods, make IS_ALPHA use LOWER internally 2011-06-20 12:42:57 -04:00
Peter Griess
9114e58a77 Facility to report detailed parsing errors.
- Add http_errno enum w/ values for many parsing error conditions. Stash
  this in http_parser.state if the 0x80 bit is set.
- Report line numbers on error generation if the (new) HTTP_PARSER_DEBUG
  cpp symbol is set. Increases http_parser struct size by 8 bytes in
  this case.
- Add http_errno_*() methods to help turning errno values into
  human-readable messages.
2011-06-19 13:25:03 -05:00
Peter Griess
056bcd3672 Merge pull request #49 from pgriess/upgrade-off-by-one
Fix off-by-one in handling upgrade bodies.
2011-06-19 10:51:23 -07:00
Peter Griess
d4ca280af5 Fix off-by-one in handling upgrade bodies.
- When handling upgraded bodies, http_parser_execute() used to return
  one fewer bytes parsed than expected. This caused the final LF to be
  interpreted by the caller as part of the body.
- Add a bunch of upgrade body unit tests.
2011-06-18 18:57:32 -05:00
Cliff Frey
d5f0312eee remove unused LOWER(ch) 2011-06-18 11:47:02 -07:00
Jon Kolb
a6934445e8 Allow uppercase chars in IS_ALPHANUM 2011-06-18 13:46:29 -04:00
Peter Griess
f684abdcc5 Merge pull request #27 from a2800276/master
lowercasing in header after check for CR LF
2011-06-11 09:36:30 -07:00
Jon Kolb
dc314a3cb9 Return error when bad method starts with M or C 2011-06-10 13:36:36 -04:00
Sean Cunningham
b89f94414e Support multi-line folding in header values.
Normal value cb is called for subsequent lines.  LWS is skipped.
  Note that \t whitespace character is now supported after header field name.

  RFC 2616, Section 2.2
  "HTTP/1.1 header field values can be folded onto multiple lines if the
   continuation line begins with a space or horizontal tab. All linear
   white space, including folding, has the same semantics as SP. A
   recipient MAY replace any linear white space with a single SP before
   interpreting the field value or forwarding the message downstream."
2011-06-03 19:25:54 -04:00
Cliff Frey
3258e4a455 Fix build when char is unsigned by default.
I tested by building/testing with -funsigned-char.  Thanks to apaprocki for
pointing out this problem.
2011-06-03 14:15:33 -07:00
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