Skip to content

Commit 6209028

Browse files
committed
Ocsigen_response: Propagate the transfer encoding
In cohttp-eio, the transfer encoding is no longer propagated through the `Body.t` type. Instead, it must be propagated separately.
1 parent a59d4aa commit 6209028

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/server/ocsigen_response.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ module Body = struct
1212
(Transfer.Fixed (Int64.of_int (String.length s)))
1313
(fun write -> write s)
1414

15-
let of_cohttp body =
16-
( (fun write -> Cohttp_lwt.Body.write_body write body)
17-
, Cohttp_lwt.Body.transfer_encoding body )
15+
let of_cohttp ~encoding body =
16+
(fun write -> Cohttp_lwt.Body.write_body write body), encoding
1817

1918
let write (w, _) = w
2019
let transfer_encoding = snd
@@ -26,16 +25,16 @@ type t =
2625
let make ?(body = Body.empty) ?(cookies = Ocsigen_cookie_map.empty) a_response =
2726
{a_response; a_body = body; a_cookies = cookies}
2827

29-
let respond ?headers ~status ?(body = Body.empty) () =
28+
let respond ?headers ~status ~encoding ?(body = Body.empty) () =
3029
let encoding =
3130
match headers with
32-
| None -> Body.transfer_encoding body
31+
| None -> encoding
3332
| Some headers -> (
3433
match Cohttp.Header.get_transfer_encoding headers with
35-
| Cohttp.Transfer.Unknown -> Body.transfer_encoding body
34+
| Cohttp.Transfer.Unknown -> encoding
3635
| t -> t)
3736
in
38-
let response = Cohttp.Response.make ~status ~encoding ?headers () in
37+
let response = Response.make ~status ~encoding ?headers () in
3938
make ~body response
4039

4140
let respond_string ?headers ~status ~body () =
@@ -57,7 +56,8 @@ let update ?response ?body ?cookies {a_response; a_body; a_cookies} =
5756
{a_response; a_body; a_cookies}
5857

5958
let of_cohttp ?(cookies = Ocsigen_cookie_map.empty) (a_response, body) =
60-
let a_body = Body.of_cohttp body in
59+
let encoding = Response.encoding a_response in
60+
let a_body = Body.of_cohttp ~encoding body in
6161
{a_response; a_body; a_cookies = cookies}
6262

6363
(* FIXME: secure *)

src/server/ocsigen_response.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Body : sig
1313
(** [make writer] makes a reponse body whose content is generated by
1414
[writer write]. [write str] blocks until [str] is fully written. *)
1515

16-
val of_cohttp : Cohttp_lwt.Body.t -> t
16+
val of_cohttp : encoding:Cohttp.Transfer.encoding -> Cohttp_lwt.Body.t -> t
1717
val write : t -> (string -> unit Lwt.t) -> unit Lwt.t
1818
val transfer_encoding : t -> Cohttp.Transfer.encoding
1919
end
@@ -27,6 +27,7 @@ val make :
2727
val respond :
2828
?headers:Cohttp.Header.t
2929
-> status:Http.Status.t
30+
-> encoding:Cohttp.Transfer.encoding
3031
-> ?body:Body.t
3132
-> unit
3233
-> t

0 commit comments

Comments
 (0)