src/server/test/httpparser.c

changeset 678
9908159eff0e
parent 677
3b8d3b37a4d5
--- a/src/server/test/httpparser.c	Tue Feb 17 13:03:39 2026 +0100
+++ b/src/server/test/httpparser.c	Tue Feb 17 17:43:10 2026 +0100
@@ -209,44 +209,78 @@
     header_array_free(header);
 }
 
+#define _CX_STR(s) { s, sizeof(s)-1 }
+
+static cxstring req0 = _CX_STR(
+    "GET / HTTP/1.1\r\n"
+    "Host: example.com\r\n"
+    "\r\n");
+
+static 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");
+
+static 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(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);
     }
 }
+
+CX_TEST(test_http_parser_process_chunk_1b) {
+    CX_TEST_DO {
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 1);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 1);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 1);
+    }
+}
+
+CX_TEST(test_http_parser_process_chunk_2b) {
+    CX_TEST_DO {
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 2);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 2);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 2);
+    }
+}
+
+CX_TEST(test_http_parser_process_chunk_3b) {
+    CX_TEST_DO {
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 3);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 3);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 3);
+    }
+}
+
+CX_TEST(test_http_parser_process_chunk_4b) {
+    CX_TEST_DO {
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 4);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 4);
+        CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 4);
+    }
+}

mercurial