Skip to content

Commit 6d7b5fe

Browse files
authored
Merge pull request #715 from mefyl/feature/fix-empty-chunks
Fix chunked encoding of empty bodies.
2 parents 45bf1a6 + 8871504 commit 6d7b5fe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cohttp/src/transfer_io.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ module Make(IO : S.IO) = struct
8080

8181
let write oc buf =
8282
let len = String.length buf in
83-
write oc (Printf.sprintf "%x\r\n" len) >>= fun () ->
84-
write oc buf >>= fun () ->
85-
write oc "\r\n"
83+
(* do NOT send empty chunks, as it signals the end of the
84+
chunked body *)
85+
if len <> 0 then
86+
write oc (Printf.sprintf "%x\r\n" len) >>= fun () ->
87+
write oc buf >>= fun () ->
88+
write oc "\r\n"
89+
else
90+
return ()
8691
end
8792

8893
module Fixed = struct

0 commit comments

Comments
 (0)