@@ -53,7 +53,8 @@ let respond_error ?headers ?(status = `Internal_server_error) ~body () =
5353let update ?response ?body ?cookies {a_response; a_body; a_cookies} =
5454 let a_response =
5555 match response with Some response -> response | None -> a_response
56- and a_body = match body with Some body -> body | None -> a_body
56+ in
57+ let a_body = match body with Some body -> body | None -> a_body
5758 and a_cookies =
5859 match cookies with Some cookies -> cookies | None -> a_cookies
5960 in
@@ -90,19 +91,25 @@ let make_cookies_headers path t hds =
9091 (make_cookies_header path exp name v secure))
9192 t hds
9293
93- let to_cohttp_response {a_response; a_cookies; a_body = _ } =
94+ let to_cohttp_response {a_response; a_cookies; a_body = _ , encoding } =
9495 let headers =
9596 let add name value headers = Header. add_unless_exists headers name value in
97+ let add_transfer_encoding h =
98+ match encoding with
99+ | Transfer. Chunked -> add " transfer-encoding" " chunked" h
100+ | _ -> h
101+ in
96102 Ocsigen_cookie_map.Map_path. fold make_cookies_headers a_cookies
97103 (Response. headers a_response)
98104 |> add " server" Ocsigen_config. server_name
99105 |> add " date" (Ocsigen_lib.Date. to_string (Unix. time () ))
106+ |> add_transfer_encoding
100107 in
101108 {a_response with Response. headers}
102109
103110let to_response_expert t =
104111 let module R = Cohttp_lwt_unix. Response in
105- let write_footer { R. encoding; _} oc =
112+ let write_footer encoding oc =
106113 (* Copied from [cohttp/response.ml]. *)
107114 match encoding with
108115 | Transfer. Chunked -> Lwt_io. write oc " 0\r\n\r\n "
@@ -112,8 +119,9 @@ let to_response_expert t =
112119 ( res
113120 , fun _ic oc ->
114121 let writer = R. make_body_writer ~flush: false res oc in
115- let * () = fst t.a_body (R. write_body writer) in
116- write_footer res oc )
122+ let body, encoding = t.a_body in
123+ let * () = body (R. write_body writer) in
124+ write_footer encoding oc )
117125
118126let response t = t.a_response
119127let body t = t.a_body
0 commit comments