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

Compress/gzip dream responses [evaluate dream-encoding library] #67

Open
mooreryan opened this issue Jun 9, 2021 · 6 comments
Open

Comments

@mooreryan
Copy link
Contributor

Hey aantron, so I've coded up a little api using dream, and one thing I can't find in the docs mentioned is if it is possible to compress/gzip responses.

Is this possible? I was thinking maybe using the stream response in combination with an ocaml gzip library.

Thanks!

@aantron
Copy link
Owner

aantron commented Jun 10, 2021

@mooreryan It is possible in principle, but I haven't looked into it in detail, picked a compression library, made any specific suggestions, etc. @tmattio has mentioned that he was interested in making a library of Dream helpers for this. Now that you've asked, I'm also considering making an example about it.

@mooreryan
Copy link
Contributor Author

Ah your tip about @tmattio seems correct...I saw this https://github.com/tmattio/dream-encoding and the Dream_encoding.compress middleware from that repo seems to work just fine for compressing responses.

@aantron
Copy link
Owner

aantron commented Jun 10, 2021

Ah nice. I'll link to it from this repo once dream-encoding is released, has proper README (as mentioned in the current README), etc. :)

@tmattio
Copy link
Contributor

tmattio commented Jun 10, 2021

Another README to write, I promise I'll get to them soon @aantron 😄

@aantron aantron changed the title Compress/gzip dream responses Compress/gzip dream responses [evaluate dream-encoding library] Jul 3, 2021
@aantron
Copy link
Owner

aantron commented Jul 8, 2021

dream-encoding is now installable from opam (and by esy), and recommended in Dream's README. For usage with large responses, Dream will need to rework the I/O a little bit (relax the types, etc.) to make it easier for middlewares to do stream processing. After that, dream-encoding should be changed internally to do streaming compression (it is ready, just needs to change the Dream functions it is calling once they are ready). So, I want to leave this issue open until that Dream I/O rework, and potentially also until there is an example in Dream that shows dream-encoding.

@cemerick
Copy link

A side note: it would be really nice if the eventual solution to this problem accounted for caching/preparing the results of compressing static resources (maybe especially those coming out of an ocaml-crunched module), so responses for unchanging content don't need to be gzipped over and over. It might be that the right solution is a general-purpose memoization middleware...

tchibanda24 pushed a commit to tchibanda24/dream that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants