Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrade http-parser to nodejs/http-parser@2498961
  • Loading branch information
ry committed Nov 22, 2011
1 parent 38c49fb commit 3abebfe
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 23 deletions.
3 changes: 0 additions & 3 deletions deps/http_parser/.gitignore
Expand Up @@ -3,6 +3,3 @@ tags
test
test_g
test_fast
http_parser.Makefile
http_parser.target.mk
test.target.mk
2 changes: 0 additions & 2 deletions deps/http_parser/CMakeLists.txt

This file was deleted.

18 changes: 10 additions & 8 deletions deps/http_parser/http_parser.c
Expand Up @@ -370,6 +370,13 @@ size_t http_parser_execute (http_parser *parser,
uint64_t index = parser->index;
uint64_t nread = parser->nread;

/* technically we could combine all of these (except for url_mark) into one
variable, saving stack space, but it seems more clear to have them
separated. */
const char *header_field_mark = 0;
const char *header_value_mark = 0;
const char *url_mark = 0;

/* We're in an error state. Don't bother doing anything. */
if (HTTP_PARSER_ERRNO(parser) != HPE_OK) {
return 0;
Expand All @@ -396,12 +403,6 @@ size_t http_parser_execute (http_parser *parser,
}
}

/* technically we could combine all of these (except for url_mark) into one
variable, saving stack space, but it seems more clear to have them
separated. */
const char *header_field_mark = 0;
const char *header_value_mark = 0;
const char *url_mark = 0;

if (state == s_header_field)
header_field_mark = data;
Expand Down Expand Up @@ -514,7 +515,7 @@ size_t http_parser_execute (http_parser *parser,
break;

case s_res_first_http_major:
if (ch < '1' || ch > '9') {
if (ch < '0' || ch > '9') {
SET_ERRNO(HPE_INVALID_VERSION);
goto error;
}
Expand Down Expand Up @@ -690,12 +691,13 @@ size_t http_parser_execute (http_parser *parser,

case s_req_method:
{
const char *matcher;
if (ch == '\0') {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}

const char *matcher = method_strings[parser->method];
matcher = method_strings[parser->method];
if (ch == ' ' && matcher[index] == '\0') {
state = s_req_spaces_before_url;
} else if (ch == matcher[index]) {
Expand Down
61 changes: 53 additions & 8 deletions deps/http_parser/http_parser.gyp
Expand Up @@ -5,24 +5,69 @@
# ./gyp/gyp -f make --depth=`pwd` http_parser.gyp
# ./out/Debug/test
{
'target_defaults': {
'default_configuration': 'Debug',
'configurations': {
# TODO: hoist these out and put them somewhere common, because
# RuntimeLibrary MUST MATCH across the entire project
'Debug': {
'defines': [ 'DEBUG', '_DEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 1, # static debug
},
},
},
'Release': {
'defines': [ 'NDEBUG' ],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': 0, # static release
},
},
}
},
'msvs_settings': {
'VCCLCompilerTool': {
},
'VCLibrarianTool': {
},
'VCLinkerTool': {
'GenerateDebugInformation': 'true',
},
},
'conditions': [
['OS == "win"', {
'defines': [
'WIN32'
],
}]
],
},

'targets': [
{
'target_name': 'http_parser',
'type': '<(library)',
'type': 'static_library',
'include_dirs': [ '.' ],
'direct_dependent_settings': {
'include_dirs': [ '.' ],
},
'defines': [ 'HTTP_PARSER_STRICT=0' ],
'sources': [ './http_parser.c', ],
'msvs_settings': {
'VCCLCompilerTool': {
# Compile as C++. http_parser.c is actually C99, but C++ is
# close enough in this case.
'CompileAs': 2, # compile as C++
},
},
'conditions': [
['OS=="win"', {
'msvs_settings': {
'VCCLCompilerTool': {
# Compile as C++. http_parser.c is actually C99, but C++ is
# close enough in this case.
'CompileAs': 2,
},
},
}]
],
},

{
'target_name': 'test',
'type': 'executable',
Expand Down
2 changes: 1 addition & 1 deletion deps/http_parser/http_parser.h
Expand Up @@ -222,7 +222,7 @@ struct http_parser {
* Should be checked when http_parser_execute() returns in addition to
* error checking.
*/
char upgrade : 1;
unsigned char upgrade : 1;

#if HTTP_PARSER_DEBUG
uint32_t error_lineno;
Expand Down
18 changes: 17 additions & 1 deletion deps/http_parser/test.c
Expand Up @@ -1041,8 +1041,24 @@ const struct message responses[] =
,.body= ""
}


#define HTTP_VERSION_0_9 12
/* Should handle HTTP/0.9 */
, {.name= "http version 0.9"
,.type= HTTP_RESPONSE
,.raw= "HTTP/0.9 200 OK\r\n"
"\r\n"
,.should_keep_alive= FALSE
,.message_complete_on_eof= TRUE
,.http_major= 0
,.http_minor= 9
,.status_code= 200
,.num_headers= 0
,.headers=
{}
,.body= ""
}
, {.name= NULL } /* sentinel */

};

int
Expand Down

0 comments on commit 3abebfe

Please sign in to comment.