Tue, 17 Feb 2026 13:03:39 +0100
add test_http_parser_process_full
--- a/src/server/test/httpparser.c Mon Feb 16 18:45:17 2026 +0100 +++ b/src/server/test/httpparser.c Tue Feb 17 13:03:39 2026 +0100 @@ -30,6 +30,8 @@ #include "../daemon/httpparser.h" +#include <cx/string.h> + CX_TEST(test_parse_request_line) { CX_TEST_DO { HttpParser parser; @@ -179,3 +181,72 @@ CX_TEST_ASSERT(nret6); } } + +CX_TEST_SUBROUTINE(test_http_parser_process, cxstring request, int chunksize) { + netbuf buf; + memset(&buf, 0, sizeof(netbuf)); + buf.inbuf = (unsigned char*)request.ptr; + buf.maxsize = request.length; + HeaderArray *header = header_array_create(); + HttpParser *parser = http_parser_new2(0, &buf, header); + + while(buf.cursize < request.length) { + buf.cursize += chunksize; + if(buf.cursize > buf.maxsize) { + buf.cursize = buf.maxsize; + } + + int ret = http_parser_process(parser); + if(buf.cursize < buf.maxsize) { + CX_TEST_ASSERT(ret == 1); + } else { + CX_TEST_ASSERT(ret == 0); + } + } + CX_TEST_ASSERT(http_parser_validate(parser)); + + http_parser_free(parser); + header_array_free(header); +} + +CX_TEST(test_http_parser_process_full) { + CX_TEST_DO { + cxstring req0 = cx_str( + "GET / HTTP/1.1\r\n" + "Host: example.com\r\n" + "\r\n"); + + cxstring req1 = cx_str("GET /api/data?id=42 HTTP/1.1\r\n" + "Host: api.example.com\r\n" + "User-Agent: TestClient/1.0\r\n" + "Accept: application/json\r\n" + "Accept-Language: en-US,en;q=0.9\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: no-cache\r\n" + "\r\n"); + + cxstring req2 = cx_str("GET /search?q=network+testing HTTP/1.1\r\n" + "Host: www.example.com\r\n" + "User-Agent: Mozilla/5.0 (X11; Linux x86_64) TestBrowser/99.0\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" + "Accept-Language: en-US,en;q=0.9,de;q=0.8\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "Pragma: no-cache\r\n" + "DNT: 1\r\n" + "Sec-Fetch-Dest: document\r\n" + "Sec-Fetch-Mode: navigate\r\n" + "Sec-Fetch-Site: none\r\n" + "Sec-Fetch-User: ?1\r\n" + "Referer: https://www.example.com/\r\n" + "X-Forwarded-For: 203.0.113.195\r\n" + "X-Request-ID: 123e4567-e89b-12d3-a456-426614174000\r\n" + "\r\n"); + + CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, req0.length); + CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, req1.length); + CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, req2.length); + } +}
--- a/src/server/test/httpparser.h Mon Feb 16 18:45:17 2026 +0100 +++ b/src/server/test/httpparser.h Tue Feb 17 13:03:39 2026 +0100 @@ -37,6 +37,7 @@ CX_TEST(test_parse_request_line); CX_TEST(test_parse_response_line); +CX_TEST(test_http_parser_process_full); #ifdef __cplusplus
--- a/src/server/test/main.c Mon Feb 16 18:45:17 2026 +0100 +++ b/src/server/test/main.c Tue Feb 17 13:03:39 2026 +0100 @@ -90,6 +90,7 @@ // httpparser tests cx_test_register(suite, test_parse_request_line); cx_test_register(suite, test_parse_response_line); + cx_test_register(suite, test_http_parser_process_full); // event tests cx_test_register(suite, test_evhandler_create);