fix(response): do not override "content-length" in raw response

close #92
This commit is contained in:
Simon Cruanes 2025-04-15 10:15:05 -04:00
parent c55e3a2dfc
commit 94c9239d64
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -15,7 +15,11 @@ let set_code code self = { self with code }
let make_raw ?(headers = []) ~code body : t =
(* add content length to response *)
let headers =
Headers.set "Content-Length" (string_of_int (String.length body)) headers
if Headers.contains "content-length" headers then
(* do not override user-provided headers (e.g. in HEAD), see #92 *)
headers
else
Headers.set "Content-Length" (string_of_int (String.length body)) headers
in
{ code; headers; body = `String body }