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

Deflate decoder doesn't handle raw deflate streams that aren't zlib-wrapped #25

Closed
insticore opened this issue Sep 23, 2020 · 3 comments · Fixed by #26
Closed

Deflate decoder doesn't handle raw deflate streams that aren't zlib-wrapped #25

insticore opened this issue Sep 23, 2020 · 3 comments · Fixed by #26

Comments

@insticore
Copy link

I use MoreBodyHandlers.decoding(BodyHandlers.ofString()), but it fails because 'nowrap' is not enabled for inflating. Could you please explain how to use the decoder with this option?

@mizosoft
Copy link
Owner

mizosoft commented Sep 23, 2020

Hi @insticore

Could you tell me what Content-Encoding the server uses? The decoder enables 'nowrap' only for gzip as it has it's own wrapping method which is handled by the decoder. deflate however is expected to be zlib-wrapped so the nowrap option is not used. I'm guessing you're hit by something like this where the server sends raw zlib bytes without the zlib-wrapping. Could you confirm that?

If that's the case maybe it's better for DeflateDecoder to auto-detect the zlib wrapper itself instead of letting the user choose between wrap and nowrap.

@insticore
Copy link
Author

Hi @mizosoft

The Content-Encoding is definitely deflate, I tested body decoding with such implementation
IOUtils.toString(new InflaterInputStream(bodyInputSteam, new Inflater(true)), StandardCharsets.UTF_8)
It works with nowrap option, but does not without it.
So when I tried to switch to MoreBodyHandlers it also failed.

@mizosoft
Copy link
Owner

It is the case then that the server sends a stream of raw zlib bytes for deflate. The best fix to this is to make DeflateDecoder auto-detect such streams and handle both wrapped and unwrapped cases. I'll make the necessary changes soon. Thanks for reporting!

@mizosoft mizosoft changed the title How can I turn on nowrap for Inflater? Deflate decoder doesn't handle raw deflate streams that aren't zlib-wrapped Sep 25, 2020
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

Successfully merging a pull request may close this issue.

2 participants