-
-
Notifications
You must be signed in to change notification settings - Fork 129
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 encoding primitives and a compression middleware #280
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I see an argument for not having this in Dream, which is this, or variants of this, are also needed on the client side (i.e., in Hyper).
@@ -0,0 +1,201 @@ | |||
(* This file is part of Dream, released under the MIT license. See LICENSE.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this file in src/unix/
? Can't we do compression/decompression "purely," i.e. in memory?
log.info (fun log -> | ||
log ~request:req "Compressing request with algorithm: %s" | ||
(algorithm_to_string algorithm)); | ||
let%lwt body = Message.body response in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: it should be possible to have a streaming compressor/decompressor with the current Dream API. I will probably write an example that does a streaming transformation of a body stream in some way, and a compressor/decompressor would be built analogously.
match algorithms with | ||
| None -> handler req | ||
| Some algorithms -> ( | ||
let%lwt body = Message.body req in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same note here about streaming)
There are OTOH, how much common functionality is there? For example, as I understand it, handling |
This essentially upstreams dream-encoding.
It adds a new dependency on
decompress
.Two new middleware are added:
And we add a new Encoding section to the API with the following functions:
I'm happy to keep this in a separate package, I'm opening a PR in case you're interested in having this upstream, but don't hesitate to close the PR if that's outside of the scope of first-class features you see.