test: add test for header size limit enforcement

This commit is contained in:
Simon Cruanes 2026-02-09 04:11:46 +00:00
parent 1f357e495a
commit d19c461e61
2 changed files with 26 additions and 1 deletions

View file

@ -1,4 +1,4 @@
(tests
(names t_util t_buf t_server t_io t_response)
(names t_util t_buf t_server t_io t_response t_headers)
(package tiny_httpd)
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))

25
tests/unit/t_headers.ml Normal file
View file

@ -0,0 +1,25 @@
open Test_util
open Tiny_httpd_core
(* Test that header size limits are enforced *)
let test_header_too_large () =
(* Create a header that's larger than 16KB *)
let large_value = String.make 20000 'x' in
let q =
"GET / HTTP/1.1\r\n\
Host: example.com\r\n\
X-Large: " ^ large_value ^ "\r\n\
\r\n"
in
let str = IO.Input.of_string q in
let client_addr = Unix.(ADDR_INET (inet_addr_loopback, 1024)) in
let buf = Buf.create () in
try
let _ = Request.Private_.parse_req_start_exn ~client_addr ~buf
~get_time_s:(fun _ -> 0.) str in
failwith "should have failed with 431"
with Common_.Bad_req (431, _) ->
() (* expected *)
let () =
test_header_too_large ()