From 9cbd66e49af3253e0139b84d3b4a0f3fa9bcdd89 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 9 Jan 2010 01:15:56 -0800 Subject: [PATCH] Support 'Proxy-Connection' header See http://www.http-stats.com/Proxy-Connection --- http_parser.c | 18 ++++++++++++++++++ test.c | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/http_parser.c b/http_parser.c index 7be4424..95afa18 100644 --- a/http_parser.c +++ b/http_parser.c @@ -97,6 +97,7 @@ static inline int message_complete_callback (http_parser *parser) return parser->on_message_complete(parser); } +#define PROXY_CONNECTION "proxy-connection" #define CONNECTION "connection" #define CONTENT_LENGTH "content-length" #define TRANSFER_ENCODING "transfer-encoding" @@ -218,6 +219,7 @@ enum header_states , h_CON , h_matching_connection + , h_matching_proxy_connection , h_matching_content_length , h_matching_transfer_encoding @@ -953,6 +955,10 @@ size_t http_parser_execute (http_parser *parser, header_state = h_C; break; + case 'p': + header_state = h_matching_proxy_connection; + break; + case 't': header_state = h_matching_transfer_encoding; break; @@ -1010,6 +1016,18 @@ size_t http_parser_execute (http_parser *parser, } break; + /* proxy-connection */ + + case h_matching_proxy_connection: + index++; + if (index > sizeof(PROXY_CONNECTION)-1 + || c != PROXY_CONNECTION[index]) { + header_state = h_general; + } else if (index == sizeof(PROXY_CONNECTION)-2) { + header_state = h_connection; + } + break; + /* content-length */ case h_matching_content_length: diff --git a/test.c b/test.c index d354742..5d0b3bd 100644 --- a/test.c +++ b/test.c @@ -597,6 +597,31 @@ const struct message responses[] = ,.body= "these headers are from http://news.ycombinator.com/" } +#define PROXY_CONNECTION 6 +, {.name="proxy connection" + ,.type= HTTP_RESPONSE + ,.raw= "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=UTF-8\r\n" + "Content-Length: 11\r\n" + "Proxy-Connection: close\r\n" + "Date: Thu, 31 Dec 2009 20:55:48 +0000\r\n" + "\r\n" + "hello world" + ,.should_keep_alive= FALSE + ,.message_complete_on_eof= FALSE + ,.http_major= 1 + ,.http_minor= 1 + ,.status_code= 200 + ,.num_headers= 4 + ,.headers= + { {"Content-Type", "text/html; charset=UTF-8" } + , {"Content-Length", "11" } + , {"Proxy-Connection", "close" } + , {"Date", "Thu, 31 Dec 2009 20:55:48 +0000"} + } + ,.body= "hello world" + } + , {.name= NULL } /* sentinel */ };