@ -44,9 +44,13 @@ struct message {
enum http_parser_type type ;
enum http_method method ;
int status_code ;
char request_path [ MAX_ELEMENT_SIZE ] ;
char request_url [ MAX_ELEMENT_SIZE ] ;
char fragment [ MAX_ELEMENT_SIZE ] ;
char query_string [ MAX_ELEMENT_SIZE ] ;
char body [ MAX_ELEMENT_SIZE ] ;
size_t body_size ;
uint16_t port ;
int num_headers ;
enum { NONE = 0 , FIELD , VALUE } last_header_element ;
char headers [ MAX_HEADERS ] [ 2 ] [ MAX_ELEMENT_SIZE ] ;
@ -83,6 +87,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /test "
, . request_url = " /test "
, . num_headers = 3
, . headers =
@ -111,6 +118,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /favicon.ico "
, . request_url = " /favicon.ico "
, . num_headers = 8
, . headers =
@ -137,6 +147,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /dumbfuck "
, . request_url = " /dumbfuck "
, . num_headers = 1
, . headers =
@ -155,6 +168,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " page=1 "
, . fragment = " posts-17408 "
, . request_path = " /forums/1/topics/2375 "
/* XXX request url does include fragment? */
, . request_url = " /forums/1/topics/2375?page=1#posts-17408 "
, . num_headers = 0
@ -171,6 +187,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /get_no_headers_no_body/world "
, . request_url = " /get_no_headers_no_body/world "
, . num_headers = 0
, . body = " "
@ -187,6 +206,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /get_one_header_no_body "
, . request_url = " /get_one_header_no_body "
, . num_headers = 1
, . headers =
@ -207,6 +229,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 0
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /get_funky_content_length_body_hello "
, . request_url = " /get_funky_content_length_body_hello "
, . num_headers = 1
, . headers =
@ -229,6 +254,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_POST
, . query_string = " q=search "
, . fragment = " hey "
, . request_path = " /post_identity_body_world "
, . request_url = " /post_identity_body_world?q=search#hey "
, . num_headers = 3
, . headers =
@ -253,6 +281,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_POST
, . query_string = " "
, . fragment = " "
, . request_path = " /post_chunked_all_your_base "
, . request_url = " /post_chunked_all_your_base "
, . num_headers = 1
, . headers =
@ -276,6 +307,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_POST
, . query_string = " "
, . fragment = " "
, . request_path = " /two_chunks_mult_zero_end "
, . request_url = " /two_chunks_mult_zero_end "
, . num_headers = 1
, . headers =
@ -301,6 +335,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_POST
, . query_string = " "
, . fragment = " "
, . request_path = " /chunked_w_trailing_headers "
, . request_url = " /chunked_w_trailing_headers "
, . num_headers = 3
, . headers =
@ -326,6 +363,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_POST
, . query_string = " "
, . fragment = " "
, . request_path = " /chunked_w_bullshit_after_length "
, . request_url = " /chunked_w_bullshit_after_length "
, . num_headers = 1
, . headers =
@ -343,6 +383,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " foo= \" bar \" "
, . fragment = " "
, . request_path = " /with_ \" stupid \" _quotes "
, . request_url = " /with_ \" stupid \" _quotes?foo= \" bar \" "
, . num_headers = 0
, . headers = { }
@ -366,6 +409,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 0
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /test "
, . request_url = " /test "
, . num_headers = 3
, . headers = { { " Host " , " 0.0.0.0:5000 " }
@ -386,6 +432,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " foo=bar?baz "
, . fragment = " "
, . request_path = " /test.cgi "
, . request_url = " /test.cgi?foo=bar?baz "
, . num_headers = 0
, . headers = { }
@ -404,6 +453,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /test "
, . request_url = " /test "
, . num_headers = 0
, . headers = { }
@ -428,6 +480,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " /demo "
, . request_url = " /demo "
, . num_headers = 7
, . upgrade = " Hot diggity dogg "
@ -456,6 +511,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 0
, . method = HTTP_CONNECT
, . query_string = " "
, . fragment = " "
, . request_path = " "
, . request_url = " 0-home0.netscape.com:443 "
, . num_headers = 2
, . upgrade = " some data \r \n and yet even more data "
@ -475,6 +533,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_REPORT
, . query_string = " "
, . fragment = " "
, . request_path = " /test "
, . request_url = " /test "
, . num_headers = 0
, . headers = { }
@ -491,6 +552,9 @@ const struct message requests[] =
, . http_major = 0
, . http_minor = 9
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " / "
, . request_url = " / "
, . num_headers = 0
, . headers = { }
@ -510,6 +574,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_MSEARCH
, . query_string = " "
, . fragment = " "
, . request_path = " * "
, . request_url = " * "
, . num_headers = 3
, . headers = { { " HOST " , " 239.255.255.250:1900 " }
@ -536,6 +603,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " / "
, . request_url = " / "
, . num_headers = 2
, . headers = { { " Line1 " , " abcdefghijklmno qrs " }
@ -555,6 +625,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " hail=all "
, . fragment = " "
, . request_path = " "
, . request_url = " http://hypnotoad.org?hail=all "
, . num_headers = 0
, . headers = { }
@ -571,7 +644,11 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " hail=all "
, . fragment = " "
, . request_path = " "
, . request_url = " http://hypnotoad.org:1234?hail=all "
, . port = 1234
, . num_headers = 0
, . headers = { }
, . body = " "
@ -587,7 +664,11 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " "
, . fragment = " "
, . request_path = " "
, . request_url = " http://hypnotoad.org:1234 "
, . port = 1234
, . num_headers = 0
, . headers = { }
, . body = " "
@ -608,6 +689,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_PATCH
, . query_string = " "
, . fragment = " "
, . request_path = " /file.txt "
, . request_url = " /file.txt "
, . num_headers = 4
, . headers = { { " Host " , " www.example.com " }
@ -630,6 +714,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 0
, . method = HTTP_CONNECT
, . query_string = " "
, . fragment = " "
, . request_path = " "
, . request_url = " HOME0.NETSCAPE.COM:443 "
, . num_headers = 2
, . upgrade = " "
@ -651,6 +738,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 1
, . method = HTTP_GET
, . query_string = " q=1 "
, . fragment = " narf "
, . request_path = " /δ¶/δt/pope "
, . request_url = " /δ¶/δt/pope?q=1#narf "
, . num_headers = 1
, . headers = { { " Host " , " github.com " }
@ -670,6 +760,9 @@ const struct message requests[] =
, . http_major = 1
, . http_minor = 0
, . method = HTTP_CONNECT
, . query_string = " "
, . fragment = " "
, . request_path = " "
, . request_url = " home_0.netscape.com:443 "
, . num_headers = 2
, . upgrade = " "
@ -1306,6 +1399,20 @@ check_num_eq (const struct message *m,
# define MESSAGE_CHECK_NUM_EQ(expected, found, prop) \
if ( ! check_num_eq ( expected , # prop , expected - > prop , found - > prop ) ) return 0
# define MESSAGE_CHECK_URL_EQ(u, expected, found, prop, fn) \
do { \
char ubuf [ 256 ] ; \
\
if ( ( u ) - > field_set & ( 1 < < ( fn ) ) ) { \
memcpy ( ubuf , ( found ) - > request_url + ( u ) - > field_data [ ( fn ) ] . off , \
( u ) - > field_data [ ( fn ) ] . len ) ; \
ubuf [ ( u ) - > field_data [ ( fn ) ] . len ] = ' \0 ' ; \
} else { \
ubuf [ 0 ] = ' \0 ' ; \
} \
\
check_str_eq ( expected , # prop , expected - > prop , ubuf ) ; \
} while ( 0 )
int
message_eq ( int index , const struct message * expected )
@ -1331,6 +1438,28 @@ message_eq (int index, const struct message *expected)
MESSAGE_CHECK_STR_EQ ( expected , m , request_url ) ;
/* Check URL components; we can't do this w/ CONNECT since it doesn't
* send us a well - formed URL .
*/
if ( * m - > request_url & & m - > method ! = HTTP_CONNECT ) {
struct http_parser_url u ;
if ( http_parser_parse_url ( m - > request_url , strlen ( m - > request_url ) , 0 , & u ) ) {
fprintf ( stderr , " \n \n *** failed to parse URL %s *** \n \n " ,
m - > request_url ) ;
exit ( 1 ) ;
}
m - > port = ( u . field_set & ( 1 < < UF_PORT ) ) ?
u . port : 0 ;
MESSAGE_CHECK_URL_EQ ( & u , expected , m , query_string , UF_QUERY ) ;
MESSAGE_CHECK_URL_EQ ( & u , expected , m , fragment , UF_FRAGMENT ) ;
MESSAGE_CHECK_URL_EQ ( & u , expected , m , request_path , UF_PATH ) ;
MESSAGE_CHECK_NUM_EQ ( expected , m , port ) ;
}
if ( expected - > body_size ) {
MESSAGE_CHECK_NUM_EQ ( expected , m , body_size ) ;
} else {