Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change default value of minor_version to -1, mor tests

  • Loading branch information...
commit d20daab7a65cd13b3d18001af52d030bd4c70c3e 1 parent 5d1cf18
@kazuho kazuho authored
Showing with 18 additions and 5 deletions.
  1. +2 −2 picohttpparser.c
  2. +7 −1 test.c
  3. +9 −2 test_response.c
View
4 picohttpparser.c
@@ -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
@@ -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;
View
8 test.c
@@ -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]); \
@@ -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)");
View
11 test_response.c
@@ -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]); \
@@ -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");
@@ -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)");
Please sign in to comment.
Something went wrong with that request. Please try again.