Skip to content

Commit

Permalink
cohttp-eio: Match body encoding with headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
mefyl committed Jan 4, 2024
1 parent afd2d23 commit 9f3fc2c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cohttp-eio/src/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let read input =
in
`Ok (request, body))
let write output response body =
let write output (response : Cohttp.Response.t) body =
let response =
let content_length =
let (Eio.Resource.T (body, ops)) = body in
Expand All @@ -67,13 +67,16 @@ let write output response body =
in
(* encoding field might be deprecated but it is still used
to compute headers and encode the body*)
match content_length with
| None ->
{ response with Cohttp.Response.encoding = Chunked }
[@ocaml.warning "-3"]
| Some size ->
match
(Cohttp.Header.get_transfer_encoding response.headers, content_length)
with
| Unknown, None ->
{ response with encoding = Chunked } [@ocaml.warning "-3"]
| Unknown, Some size ->
{ response with encoding = Fixed (Int64.of_int size) }
[@ocaml.warning "-3"]
| from_headers, _ ->
{ response with encoding = from_headers } [@ocaml.warning "-3"]
in
let () = Logs.debug (fun m -> m "send headers") in
let () =
Expand Down

0 comments on commit 9f3fc2c

Please sign in to comment.