fix: set transfer-encoding header when returning a chunked stream

This commit is contained in:
Simon Cruanes 2020-05-27 21:39:43 -04:00
parent 4a83a2f07f
commit 4f730ec7b6

View file

@ -619,7 +619,16 @@ module Response = struct
let output_ (oc:out_channel) (self:t) : unit = let output_ (oc:out_channel) (self:t) : unit =
Printf.fprintf oc "HTTP/1.1 %d %s\r\n" self.code (Response_code.descr self.code); Printf.fprintf oc "HTTP/1.1 %d %s\r\n" self.code (Response_code.descr self.code);
List.iter (fun (k,v) -> Printf.fprintf oc "%s: %s\r\n" k v) self.headers; let is_chunked = match self.body with
| `String _ -> false
| `Stream _ -> true
in
let headers =
if is_chunked
then Headers.set "transfer-encoding" "chunked" self.headers
else self.headers
in
List.iter (fun (k,v) -> Printf.fprintf oc "%s: %s\r\n" k v) headers;
output_string oc "\r\n"; output_string oc "\r\n";
begin match self.body with begin match self.body with
| `String "" -> () | `String "" -> ()