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

GZipResponseStream should not buffer whole request #638

Open
gkresic opened this issue Feb 15, 2023 · 1 comment
Open

GZipResponseStream should not buffer whole request #638

gkresic opened this issue Feb 15, 2023 · 1 comment

Comments

@gkresic
Copy link
Contributor

gkresic commented Feb 15, 2023

As currently implemented, GZipResponseStream buffers whole response and compresses it only upon closing:

https://github.com/pippo-java/pippo/blob/master/pippo-core/src/main/java/ro/pippo/core/gzip/GZipResponseStream.java

This may result in HUGE heap usage when streaming BIG responses, which is primary use case for using compression in responses.

Instead, it should wrap response.getOutputStream() and simply pump content to it. Even better, use some threshold and buffer responses under it, compressing only if response size end up to be over that threshold.

Idea for better implementation:

https://github.com/oblac/jodd/blob/master/jodd-servlet/src/main/java/jodd/servlet/filter/GzipResponseStream.java

@mhagnumdw
Copy link
Member

I agree!

byte[] bytes = byteArrayOutputStream.toByteArray(); is bad!

ps: I haven't looked into the suggested implementation in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants