mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 19:25:32 -05:00
fix: do not output a content-length for a chunked response
This commit is contained in:
parent
fdd97744e0
commit
6d01b5347e
1 changed files with 8 additions and 4 deletions
|
|
@ -620,17 +620,21 @@ 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);
|
||||||
let body, is_chunked = match self.body with
|
let body, is_chunked = match self.body with
|
||||||
| `String s when String.length s > 1024 * 300 ->
|
| `String s when String.length s > 1024 * 500 ->
|
||||||
(* chunk-encode large bodies *)
|
(* chunk-encode large bodies *)
|
||||||
`Stream (Byte_stream.of_string s), true
|
`Stream (Byte_stream.of_string s), true
|
||||||
| `String _ as b -> b, false
|
| `String _ as b -> b, false
|
||||||
| `Stream _ as b -> b, true
|
| `Stream _ as b -> b, true
|
||||||
in
|
in
|
||||||
let headers =
|
let headers =
|
||||||
if is_chunked
|
if is_chunked then (
|
||||||
then Headers.set "transfer-encoding" "chunked" self.headers
|
self.headers
|
||||||
else self.headers
|
|> Headers.set "transfer-encoding" "chunked"
|
||||||
|
|> Headers.remove "content-length"
|
||||||
|
) else self.headers
|
||||||
in
|
in
|
||||||
|
let self = {self with headers; body} in
|
||||||
|
_debug (fun k->k "output response: %s" (Format.asprintf "%a" pp self));
|
||||||
List.iter (fun (k,v) -> Printf.fprintf oc "%s: %s\r\n" k v) headers;
|
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 body with
|
begin match body with
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue