add httpclient test for handling an incorrect content length default tip

Sun, 01 Mar 2026 10:34:54 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 Mar 2026 10:34:54 +0100
changeset 711
5d137756c94c
parent 710
435dd6f3cbbf

add httpclient test for handling an incorrect content length

src/server/test/httpclient.c file | annotate | diff | comparison | revisions
src/server/test/httpclient.h file | annotate | diff | comparison | revisions
src/server/test/main.c file | annotate | diff | comparison | revisions
--- a/src/server/test/httpclient.c	Sat Feb 28 20:20:48 2026 +0100
+++ b/src/server/test/httpclient.c	Sun Mar 01 10:34:54 2026 +0100
@@ -294,3 +294,20 @@
         free(req_body);
     }
 }
+
+CX_TEST(test_http_client_get_incorrect_ctlen) {
+    CX_TEST_DO {
+        cxstring response = cx_str(
+                "HTTP/1.1 200 OK\r\n"
+                "Content-length: 5\r\n"
+                "\r\n"
+                "Hello World!\n");
+        CxBuffer *out = cxBufferCreate(NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS);
+        
+        CX_TEST_CALL_SUBROUTINE(test_httpclient, cx_str(NULL), FALSE, &response, 1, out);
+        CX_TEST_ASSERT(!cx_strcmp(cx_strn(out->space, out->size), "Hello"));
+        
+        cxBufferFree(out);
+    }
+}
+
--- a/src/server/test/httpclient.h	Sat Feb 28 20:20:48 2026 +0100
+++ b/src/server/test/httpclient.h	Sun Mar 01 10:34:54 2026 +0100
@@ -45,7 +45,7 @@
 CX_TEST(test_http_client_post_ctlen);
 CX_TEST(test_http_client_post_ctlen_large);
 CX_TEST(test_http_client_post_chunked);
-
+CX_TEST(test_http_client_get_incorrect_ctlen);
 
 #ifdef __cplusplus
 }
--- a/src/server/test/main.c	Sat Feb 28 20:20:48 2026 +0100
+++ b/src/server/test/main.c	Sun Mar 01 10:34:54 2026 +0100
@@ -217,6 +217,7 @@
     cx_test_register(suite, test_http_client_post_ctlen);
     cx_test_register(suite, test_http_client_post_chunked);
     cx_test_register(suite, test_http_client_post_ctlen_large);
+    cx_test_register(suite, test_http_client_get_incorrect_ctlen);
     
     // plugin tests
 #ifdef ENABLE_POSTGRESQL

mercurial