diff --git a/http_parser.h b/http_parser.h index 7d46cdf..02cb8ad 100644 --- a/http_parser.h +++ b/http_parser.h @@ -67,6 +67,11 @@ typedef int (*http_cb) (http_parser*); enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE }; +#define HTTP_VERSION_OTHER 0x00 +#define HTTP_VERSION_11 0x01 +#define HTTP_VERSION_10 0x02 +#define HTTP_VERSION_09 0x04 + struct http_parser { /** PRIVATE **/ int cs; @@ -111,8 +116,7 @@ struct http_parser { unsigned short status_code; /* responses only */ unsigned short method; /* requests only */ short transfer_encoding; - unsigned short version_major; - unsigned short version_minor; + short version; short keep_alive; size_t content_length; @@ -148,10 +152,7 @@ int http_parser_has_error (http_parser *parser); static inline int http_parser_should_keep_alive (http_parser *parser) { - if (parser->keep_alive == -1) { - if (parser->version_major == 1) return (parser->version_minor != 0); - return 0; - } + if (parser->keep_alive == -1) return (parser->version == HTTP_VERSION_11); return parser->keep_alive; } diff --git a/http_parser.rl b/http_parser.rl index 8cc6118..5bc21db 100644 --- a/http_parser.rl +++ b/http_parser.rl @@ -73,8 +73,7 @@ do { \ parser->status_code = 0; \ parser->method = 0; \ parser->transfer_encoding = HTTP_IDENTITY; \ - parser->version_major = 0; \ - parser->version_minor = 0; \ + parser->version = HTTP_VERSION_OTHER; \ parser->keep_alive = -1; \ parser->content_length = 0; \ parser->body_read = 0 @@ -242,15 +241,9 @@ do { \ action set_keep_alive { parser->keep_alive = 1; } action set_not_keep_alive { parser->keep_alive = 0; } - action version_major { - parser->version_major *= 10; - parser->version_major += *p - '0'; - } - - action version_minor { - parser->version_minor *= 10; - parser->version_minor += *p - '0'; - } + action version_11 { parser->version = HTTP_VERSION_11; } + action version_10 { parser->version = HTTP_VERSION_10; } + action version_09 { parser->version = HTTP_VERSION_09; } action add_to_chunk_size { parser->chunk_size *= 16; @@ -344,7 +337,11 @@ do { \ | "UNLOCK" %{ parser->method = HTTP_UNLOCK; } ); # Not allowing extension methods - HTTP_Version = "HTTP/" digit $version_major "." digit $version_minor; + HTTP_Version = "HTTP/" ( "1.1" %version_11 + | "1.0" %version_10 + | "0.9" %version_09 + | (digit "." digit) + ); scheme = ( alpha | digit | "+" | "-" | "." )* ; absolute_uri = (scheme ":" (uchar | reserved )*);