http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

commit 9f67ed0c4a5dec754fc68e0b7903cf413bada14a
parent 00425ff0c4469cf632626ffca0b51671081a4aa5
Author: finwo <finwo@pm.me>
Date:   Sun, 18 Feb 2024 20:43:52 +0100

Added basic testing for headers

Diffstat:
M.gitignore | 1+
Mtest.c | 2++
2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ /lib *.o http-parser-test +/.cache/ diff --git a/test.c b/test.c @@ -122,6 +122,7 @@ int main() { ASSERT("request->method is null", request->method == NULL); ASSERT("request->body is null", request->body == NULL); ASSERT("request->chunksize is -1", request->chunksize == -1); + ASSERT("request->header->host is NULL", http_parser_header_get(request, "host") == NULL); http_parser_message_free(request); request = http_parser_request_init(); @@ -137,6 +138,7 @@ int main() { ASSERT("request->path is /foobar", strcmp(request->path, "/foobar") == 0); msgbuf = http_parser_sprint_request(request); ASSERT("request->toString matches", strcmp(getMessage, msgbuf->data) == 0); + ASSERT("request->header->host is localhost", strcmp(http_parser_header_get(request, "host"), "localhost") == 0); http_parser_message_free(request); request = http_parser_request_init();