From 0264a0aefcd119e179a3bc730ac517efbbccd4bb Mon Sep 17 00:00:00 2001 From: Santiago Gala Date: Sat, 17 Jul 2010 01:20:48 -0700 Subject: [PATCH] Upgrade on CONNECT method --- http_parser.c | 4 ++-- test.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/http_parser.c b/http_parser.c index a3021cf9..834c5b25 100644 --- a/http_parser.c +++ b/http_parser.c @@ -1316,7 +1316,7 @@ size_t http_parser_execute (http_parser *parser, nread = 0; - if (parser->flags & F_UPGRADE) parser->upgrade = 1; + if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) parser->upgrade = 1; /* Here we call the headers_complete callback. This is somewhat * different than other callbacks because if the user returns 1, we @@ -1339,7 +1339,7 @@ size_t http_parser_execute (http_parser *parser, } // Exit, the rest of the connect is in a different protocol. - if (parser->flags & F_UPGRADE) { + if (parser->flags & F_UPGRADE || parser->method == HTTP_CONNECT) { CALLBACK2(message_complete); return (p - data); } diff --git a/test.c b/test.c index 6d501d60..864b2895 100644 --- a/test.c +++ b/test.c @@ -512,7 +512,7 @@ const struct message requests[] = ,.request_path= "" ,.request_url= "home.netscape.com:443" ,.num_headers= 2 - ,.upgrade=0 + ,.upgrade=1 ,.headers= { { "User-agent", "Mozilla/1.1N" } , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" } } @@ -1407,18 +1407,27 @@ test_scan (const struct message *r1, const struct message *r2, const struct mess buf3[buf3_len] = 0; read = parse(buf1, buf1_len); + + if (r3->upgrade && parser->upgrade) goto test; + if (read != buf1_len) { print_error(buf1, read); goto error; } read = parse(buf2, buf2_len); + + if (r3->upgrade && parser->upgrade) goto test; + if (read != buf2_len) { print_error(buf2, read); goto error; } read = parse(buf3, buf3_len); + + if (r3->upgrade && parser->upgrade) goto test; + if (read != buf3_len) { print_error(buf3, read); goto error; @@ -1426,6 +1435,8 @@ test_scan (const struct message *r1, const struct message *r2, const struct mess parse(NULL, 0); +test: + if (3 != num_messages) { fprintf(stderr, "\n\nParser didn't see 3 messages only %d\n", num_messages); goto error; @@ -1595,7 +1606,7 @@ main (void) "HEAD", "POST", "PUT", - "CONNECT", + //"CONNECT", //CONNECT can't be tested like other methods, it's a tunnel "OPTIONS", "TRACE", "COPY",