Skip to content

Commit

Permalink
change default value of minor_version to -1, mor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed May 11, 2010
1 parent 5d1cf18 commit d20daab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions picohttpparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int phr_parse_request(const char* buf_start, size_t len, const char** method,
*method_len = 0;
*path = NULL;
*path_len = 0;
*minor_version = 0;
*minor_version = -1;
*num_headers = 0;

/* if last_len != 0, check if the request is complete (a fast countermeasure
Expand Down Expand Up @@ -266,7 +266,7 @@ int phr_parse_response(const char* buf_start, size_t len, int* minor_version,
size_t max_headers = *num_headers;
int r;

*minor_version = 0;
*minor_version = -1;
*status = 0;
*msg = NULL;
*msg_len = 0;
Expand Down
8 changes: 7 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(void)
struct phr_header headers[4];
size_t num_headers;

tests(36);
tests(42);

#define PARSE(s, last_len, exp, comment) \
num_headers = sizeof(headers) / sizeof(headers[0]); \
Expand Down Expand Up @@ -73,13 +73,19 @@ int main(void)
"header #3 value");

PARSE("GET", 0, -2, "incomplete 1");
ok(method == NULL, "method not ready");
PARSE("GET ", 0, -2, "incomplete 2");
ok(strrcmp(method, method_len, "GET"), "method ready");
PARSE("GET /", 0, -2, "incomplete 3");
ok(path == NULL, "path not ready");
PARSE("GET / ", 0, -2, "incomplete 4");
ok(strrcmp(path, path_len, "/"), "path ready");
PARSE("GET / H", 0, -2, "incomplete 5");
PARSE("GET / HTTP/1.", 0, -2, "incomplete 6");
PARSE("GET / HTTP/1.0", 0, -2, "incomplete 7");
ok(minor_version == -1, "version not ready");
PARSE("GET / HTTP/1.0\r", 0, -2, "incomplete 8");
ok(minor_version == 0, "version is ready");

PARSE("GET /hoge HTTP/1.0\r\n\r", strlen("GET /hoge HTTP/1.0\r\n\r") - 1,
-2, "slowloris (incomplete)");
Expand Down
11 changes: 9 additions & 2 deletions test_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(void)
struct phr_header headers[4];
size_t num_headers;

tests(47);
tests(61);

#define PARSE(s, last_len, exp, comment) \
num_headers = sizeof(headers) / sizeof(headers[0]); \
Expand Down Expand Up @@ -82,7 +82,7 @@ int main(void)
PARSE("H", 0, -2, "incomplete 1");
PARSE("HTTP/1.", 0, -2, "incomplete 2");
PARSE("HTTP/1.1", 0, -2, "incomplete 3");
ok(minor_version == 0, "minor_version not ready");
ok(minor_version == -1, "minor_version not ready");
PARSE("HTTP/1.1 ", 0, -2, "incomplete 4");
ok(minor_version == 1, "minor_version ready");
PARSE("HTTP/1.1 2", 0, -2, "incomplete 5");
Expand All @@ -97,6 +97,13 @@ int main(void)
ok(strrcmp(msg, msg_len, "OK"), "message ready");
PARSE("HTTP/1.1 200 OK\n", 0, -2, "incomplete 11");
ok(strrcmp(msg, msg_len, "OK"), "message ready 2");

PARSE("HTTP/1.1 200 OK\r\nA: 1\r", 0, -2, "incomplete 11");
ok(num_headers == 0, "header not ready");
PARSE("HTTP/1.1 200 OK\r\nA: 1\r\n", 0, -2, "incomplete 12");
ok(num_headers == 1, "header ready");
ok(strrcmp(headers[0].name, headers[0].name_len, "A"), "header #1 name");
ok(strrcmp(headers[0].value, headers[0].value_len, "1"), "header #1 value");

PARSE("HTTP/1.0 200 OK\r\n\r", strlen("GET /hoge HTTP/1.0\r\n\r") - 1,
-2, "slowloris (incomplete)");
Expand Down

0 comments on commit d20daab

Please sign in to comment.