-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
fix(compress): don't compress server-sent events #3833
Conversation
Nice work |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3833 +/- ##
=======================================
Coverage 91.71% 91.71%
=======================================
Files 160 160
Lines 10195 10195
Branches 2925 2868 -57
=======================================
Hits 9350 9350
Misses 844 844
Partials 1 1 ☔ View full report in Codecov by Sentry. |
Hi @dmitri-gb Thank you for the PR. I also realized that the problem and your idea are good! As @EdamAme-x mentioned, you need to add a test. I think it's a little unsuitable if you add it to |
Using both `compress` middleware and the `streamSSE` helper from `hono/streaming` doesn't work correctly -- the SSE messages are not streamed, instead they get buffered by the compression mechanism. According to [expressjs/compression](https://github.com/expressjs/compression#server-sent-events), it should possible to compress server-sent events, if the underlying compression mechanism supports manual _flushing_. As far as I can tell though, `CompressionStream` (used by Hono's `compress` middleware) doesn't offer this functionality, so the best we can do is not compress SSE streams at all.
Hi! I added a test 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.
LGTM!
Great! Thank you for your contribution. |
related issues for tracking ability to control flushing on |
Using both
compress
middleware and thestreamSSE
helper fromhono/streaming
doesn't work correctly -- the SSE messages are not streamed, instead they get buffered by the compression mechanism.According to expressjs/compression it should be possible to compress server-sent events, if the underlying compression mechanism supports manual flushing. As far as I can tell though,
CompressionStream
(used by Hono'scompress
middleware) doesn't offer this functionality, so the best we can do is not compress SSE streams at all.