|
|
|
@ -44,6 +44,7 @@ struct message {
|
|
|
|
|
enum http_parser_type type;
|
|
|
|
|
enum http_method method;
|
|
|
|
|
int status_code;
|
|
|
|
|
char response_status[MAX_ELEMENT_SIZE];
|
|
|
|
|
char request_path[MAX_ELEMENT_SIZE];
|
|
|
|
|
char request_url[MAX_ELEMENT_SIZE];
|
|
|
|
|
char fragment[MAX_ELEMENT_SIZE];
|
|
|
|
@ -927,6 +928,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 301
|
|
|
|
|
,.response_status= "Moved Permanently"
|
|
|
|
|
,.num_headers= 8
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Location", "http://www.google.com/" }
|
|
|
|
@ -975,6 +977,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 5
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Date", "Tue, 04 Aug 2009 07:59:32 GMT" }
|
|
|
|
@ -1003,6 +1006,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 404
|
|
|
|
|
,.response_status= "Not Found"
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers= {}
|
|
|
|
|
,.body_size= 0
|
|
|
|
@ -1018,6 +1022,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 301
|
|
|
|
|
,.response_status= ""
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers= {}
|
|
|
|
|
,.body= ""
|
|
|
|
@ -1043,6 +1048,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 2
|
|
|
|
|
,.headers=
|
|
|
|
|
{ {"Content-Type", "text/plain" }
|
|
|
|
@ -1068,6 +1074,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 2
|
|
|
|
|
,.headers=
|
|
|
|
|
{ {"Content-Type", "text/html; charset=utf-8" }
|
|
|
|
@ -1091,6 +1098,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 4
|
|
|
|
|
,.headers=
|
|
|
|
|
{ {"Content-Type", "text/html; charset=UTF-8" }
|
|
|
|
@ -1116,6 +1124,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 4
|
|
|
|
|
,.headers=
|
|
|
|
|
{ {"Server", "DCLK-AdSvr" }
|
|
|
|
@ -1148,6 +1157,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 0
|
|
|
|
|
,.status_code= 301
|
|
|
|
|
,.response_status= "Moved Permanently"
|
|
|
|
|
,.num_headers= 9
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Date", "Thu, 03 Jun 2010 09:56:32 GMT" }
|
|
|
|
@ -1186,6 +1196,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 11
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Date", "Tue, 28 Sep 2010 01:14:13 GMT" }
|
|
|
|
@ -1217,6 +1228,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 500
|
|
|
|
|
,.response_status= "Oriëntatieprobleem"
|
|
|
|
|
,.num_headers= 3
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Date", "Fri, 5 Nov 2010 23:07:12 GMT+2" }
|
|
|
|
@ -1237,6 +1249,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 0
|
|
|
|
|
,.http_minor= 9
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers=
|
|
|
|
|
{}
|
|
|
|
@ -1259,6 +1272,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 1
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Content-Type", "text/plain" }
|
|
|
|
@ -1277,6 +1291,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 0
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 1
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Connection", "keep-alive" }
|
|
|
|
@ -1296,6 +1311,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 0
|
|
|
|
|
,.status_code= 204
|
|
|
|
|
,.response_status= "No content"
|
|
|
|
|
,.num_headers= 1
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Connection", "keep-alive" }
|
|
|
|
@ -1314,6 +1330,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers={}
|
|
|
|
|
,.body_size= 0
|
|
|
|
@ -1330,6 +1347,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 204
|
|
|
|
|
,.response_status= "No content"
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers={}
|
|
|
|
|
,.body_size= 0
|
|
|
|
@ -1347,6 +1365,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 204
|
|
|
|
|
,.response_status= "No content"
|
|
|
|
|
,.num_headers= 1
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Connection", "close" }
|
|
|
|
@ -1368,6 +1387,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 1
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Transfer-Encoding", "chunked" }
|
|
|
|
@ -1396,6 +1416,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 7
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Server", "Microsoft-IIS/6.0" }
|
|
|
|
@ -1433,6 +1454,7 @@ const struct message responses[] =
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 301
|
|
|
|
|
,.response_status= "MovedPermanently"
|
|
|
|
|
,.num_headers= 9
|
|
|
|
|
,.headers= { { "Date", "Wed, 15 May 2013 17:06:33 GMT" }
|
|
|
|
|
, { "Server", "Server" }
|
|
|
|
@ -1447,6 +1469,22 @@ const struct message responses[] =
|
|
|
|
|
,.body= "\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMPTY_REASON_PHRASE_AFTER_SPACE 20
|
|
|
|
|
, {.name= "empty reason phrase after space"
|
|
|
|
|
,.type= HTTP_RESPONSE
|
|
|
|
|
,.raw= "HTTP/1.1 200 \r\n"
|
|
|
|
|
"\r\n"
|
|
|
|
|
,.should_keep_alive= FALSE
|
|
|
|
|
,.message_complete_on_eof= TRUE
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 1
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= ""
|
|
|
|
|
,.num_headers= 0
|
|
|
|
|
,.headers= {}
|
|
|
|
|
,.body= ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
, {.name= NULL } /* sentinel */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -1528,13 +1566,6 @@ request_url_cb (http_parser *p, const char *buf, size_t len)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
status_complete_cb (http_parser *p) {
|
|
|
|
|
assert(p == parser);
|
|
|
|
|
p->data++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
header_field_cb (http_parser *p, const char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
@ -1660,6 +1691,17 @@ message_complete_cb (http_parser *p)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
response_status_cb (http_parser *p, const char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
assert(p == parser);
|
|
|
|
|
strlncat(messages[num_messages].response_status,
|
|
|
|
|
sizeof(messages[num_messages].response_status),
|
|
|
|
|
buf,
|
|
|
|
|
len);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* These dontcall_* callbacks exist so that we can verify that when we're
|
|
|
|
|
* paused, no additional callbacks are invoked */
|
|
|
|
|
int
|
|
|
|
@ -1720,11 +1762,20 @@ dontcall_message_complete_cb (http_parser *p)
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
dontcall_response_status_cb (http_parser *p, const char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
if (p || buf || len) { } // gcc
|
|
|
|
|
fprintf(stderr, "\n\n*** on_status() called on paused parser ***\n\n");
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static http_parser_settings settings_dontcall =
|
|
|
|
|
{.on_message_begin = dontcall_message_begin_cb
|
|
|
|
|
,.on_header_field = dontcall_header_field_cb
|
|
|
|
|
,.on_header_value = dontcall_header_value_cb
|
|
|
|
|
,.on_url = dontcall_request_url_cb
|
|
|
|
|
,.on_status = dontcall_response_status_cb
|
|
|
|
|
,.on_body = dontcall_body_cb
|
|
|
|
|
,.on_headers_complete = dontcall_headers_complete_cb
|
|
|
|
|
,.on_message_complete = dontcall_message_complete_cb
|
|
|
|
@ -1790,11 +1841,20 @@ pause_message_complete_cb (http_parser *p)
|
|
|
|
|
return message_complete_cb(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
pause_response_status_cb (http_parser *p, const char *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
http_parser_pause(p, 1);
|
|
|
|
|
*current_pause_parser = settings_dontcall;
|
|
|
|
|
return response_status_cb(p, buf, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static http_parser_settings settings_pause =
|
|
|
|
|
{.on_message_begin = pause_message_begin_cb
|
|
|
|
|
,.on_header_field = pause_header_field_cb
|
|
|
|
|
,.on_header_value = pause_header_value_cb
|
|
|
|
|
,.on_url = pause_request_url_cb
|
|
|
|
|
,.on_status = pause_response_status_cb
|
|
|
|
|
,.on_body = pause_body_cb
|
|
|
|
|
,.on_headers_complete = pause_headers_complete_cb
|
|
|
|
|
,.on_message_complete = pause_message_complete_cb
|
|
|
|
@ -1805,6 +1865,7 @@ static http_parser_settings settings =
|
|
|
|
|
,.on_header_field = header_field_cb
|
|
|
|
|
,.on_header_value = header_value_cb
|
|
|
|
|
,.on_url = request_url_cb
|
|
|
|
|
,.on_status = response_status_cb
|
|
|
|
|
,.on_body = body_cb
|
|
|
|
|
,.on_headers_complete = headers_complete_cb
|
|
|
|
|
,.on_message_complete = message_complete_cb
|
|
|
|
@ -1815,6 +1876,7 @@ static http_parser_settings settings_count_body =
|
|
|
|
|
,.on_header_field = header_field_cb
|
|
|
|
|
,.on_header_value = header_value_cb
|
|
|
|
|
,.on_url = request_url_cb
|
|
|
|
|
,.on_status = response_status_cb
|
|
|
|
|
,.on_body = count_body_cb
|
|
|
|
|
,.on_headers_complete = headers_complete_cb
|
|
|
|
|
,.on_message_complete = message_complete_cb
|
|
|
|
@ -1825,6 +1887,7 @@ static http_parser_settings settings_null =
|
|
|
|
|
,.on_header_field = 0
|
|
|
|
|
,.on_header_value = 0
|
|
|
|
|
,.on_url = 0
|
|
|
|
|
,.on_status = 0
|
|
|
|
|
,.on_body = 0
|
|
|
|
|
,.on_headers_complete = 0
|
|
|
|
|
,.on_message_complete = 0
|
|
|
|
@ -1948,6 +2011,7 @@ message_eq (int index, const struct message *expected)
|
|
|
|
|
MESSAGE_CHECK_NUM_EQ(expected, m, method);
|
|
|
|
|
} else {
|
|
|
|
|
MESSAGE_CHECK_NUM_EQ(expected, m, status_code);
|
|
|
|
|
MESSAGE_CHECK_STR_EQ(expected, m, response_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MESSAGE_CHECK_NUM_EQ(expected, m, should_keep_alive);
|
|
|
|
@ -3133,20 +3197,6 @@ create_large_chunked_message (int body_size_in_kb, const char* headers)
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
test_status_complete (void)
|
|
|
|
|
{
|
|
|
|
|
parser_init(HTTP_RESPONSE);
|
|
|
|
|
parser->data = 0;
|
|
|
|
|
http_parser_settings settings = settings_null;
|
|
|
|
|
settings.on_status_complete = status_complete_cb;
|
|
|
|
|
|
|
|
|
|
char *response = "don't mind me, just a simple response";
|
|
|
|
|
http_parser_execute(parser, &settings, response, strlen(response));
|
|
|
|
|
assert(parser->data == (void*)0); // the status_complete callback was never called
|
|
|
|
|
assert(parser->http_errno == HPE_INVALID_CONSTANT); // the errno for an invalid status line
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Verify that we can pause parsing at any of the bytes in the
|
|
|
|
|
* message and still get the result that we're expecting. */
|
|
|
|
|
void
|
|
|
|
@ -3280,6 +3330,7 @@ main (void)
|
|
|
|
|
,.http_major= 1
|
|
|
|
|
,.http_minor= 0
|
|
|
|
|
,.status_code= 200
|
|
|
|
|
,.response_status= "OK"
|
|
|
|
|
,.num_headers= 2
|
|
|
|
|
,.headers=
|
|
|
|
|
{ { "Transfer-Encoding", "chunked" }
|
|
|
|
@ -3468,8 +3519,6 @@ main (void)
|
|
|
|
|
, &requests[CONNECT_REQUEST]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
test_status_complete();
|
|
|
|
|
|
|
|
|
|
puts("requests okay");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|