Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for gzip + chunked #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add support for gzip + chunked
tatchi committed May 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 823d59d27dc913671b7ed03ba32b89012e9d21df
7 changes: 6 additions & 1 deletion httpev.ml
Original file line number Diff line number Diff line change
@@ -930,11 +930,12 @@ let send_reply c cout reply =
(* possibly apply encoding *)
let%lwt (hdrs,body) =
(* TODO do not apply encoding to application/gzip *)
(* TODO gzip + chunked? *)
match body, code, c.req with
| `Body s, `Ok, Ready { encoding=Gzip; _ } when String.length s > 128 ->
let%lwt body = Gzip_io.string_lwt s in
Lwt.return (("Content-Encoding", "gzip")::hdrs, `Body body)
| `Chunks _ as body, `Ok, Ready { encoding=Gzip; _ } ->
Lwt.return (("Content-Encoding", "gzip")::hdrs, body)
| _ -> Lwt.return (hdrs, body)
in
let hdrs = match body with
@@ -957,6 +958,10 @@ let send_reply c cout reply =
let push = function
| "" -> Lwt.return_unit
| s ->
let%lwt s = match c.req with
| Ready { encoding=Gzip; _ } -> Gzip_io.string_lwt s
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right.
If I'm reading correctly you're Gzip-encoding each chunk. But that's not how it's meant to happen.
Compression precedes the chunking.

| _ -> Lwt.return s
in
let%lwt () = Lwt_io.write cout (sprintf "%x\r\n" (String.length s)) in
let%lwt () = Lwt_io.write cout s in
Lwt_io.write cout "\r\n"