From 7898f1a97ad8c5749a4a956d2d6506ff5436430c Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 27 Apr 2009 16:54:09 +0200 Subject: [PATCH] add http_parser_should_keep_alive() --- http_parser.h | 2 +- http_parser.rl | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/http_parser.h b/http_parser.h index 64193cd..9b48164 100644 --- a/http_parser.h +++ b/http_parser.h @@ -121,7 +121,7 @@ size_t http_parser_execute (http_parser *parser, const char *data, size_t len); int http_parser_has_error (http_parser *parser); -int http_message_should_keep_alive (http_parser *message); +int http_parser_should_keep_alive (http_parser *parser); #define http_message_has_body(parser) \ (parser->transfer_encoding == HTTP_CHUNKED || parser->content_length > 0 ) diff --git a/http_parser.rl b/http_parser.rl index 130af23..801a982 100644 --- a/http_parser.rl +++ b/http_parser.rl @@ -65,7 +65,7 @@ static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 parser->version_major = 0; \ parser->version_minor = 0; \ parser->number_of_headers = 0; \ - parser->keep_alive = 0; \ + parser->keep_alive = -1; \ parser->content_length = 0; \ parser->body_read = 0; @@ -146,15 +146,17 @@ do { \ } action headers_complete { - if(parser->on_headers_complete) + if(parser->on_headers_complete) { callback_return_value = parser->on_headers_complete(parser); - if (callback_return_value != 0) fbreak; + if (callback_return_value != 0) fbreak; + } } action begin_message { - if(parser->on_message_begin) + if(parser->on_message_begin) { callback_return_value = parser->on_message_begin(parser); - if (callback_return_value != 0) fbreak; + if (callback_return_value != 0) fbreak; + } } action content_length { @@ -401,18 +403,16 @@ http_parser_has_error (http_parser *parser) return parser->cs == http_parser_error; } -#if 0 int -http_should_keep_alive (http *request) +http_parser_should_keep_alive (http_parser *parser) { - if (request->keep_alive == -1) - if (request->version_major == 1) - return (request->version_minor != 0); - else if (request->version_major == 0) + if (parser->keep_alive == -1) + if (parser->version_major == 1) + return (parser->version_minor != 0); + else if (parser->version_major == 0) return FALSE; else return TRUE; else - return request->keep_alive; + return parser->keep_alive; } -#endif