mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
fix: set transfer-encoding header when returning a chunked stream
This commit is contained in:
parent
4a83a2f07f
commit
4f730ec7b6
1 changed files with 10 additions and 1 deletions
|
|
@ -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 "" -> ()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue