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

Add support for deflate decompression #275

Closed
wants to merge 1 commit into from

Conversation

s3cur3
Copy link

@s3cur3 s3cur3 commented Nov 24, 2023

EDIT: Oh! I see this was intentionally removed in the past. Feel free to close!

This adds support for responses that were compressed using the deflate algorithm.

As best I can tell, this isn't terribly common for servers to send in the wild—in my own usage of Req for scraping public sites, I see gzip and Brotli way, way more frequently. However, I think it's useful to have in Req for the sake of having decompression support that matches real browsers; Safari, Firefox, and Chrome each send an Accept-Encoding header of gzip, deflate, br.

This adds support for responses that were compressed using the `deflate` algorithm.

As best I can tell, this isn't terribly common for servers to send in the wild—in my own usage of Req for scraping public sites, I see gzip and Brotli way, way more frequently. However, I think it's useful to have in Req for the sake of having decompression support that matches real browsers; Safari, Firefox, and Chrome each send an `Accept-Encoding` header of `gzip, deflate, br`.
Comment on lines +1346 to +1353
# uncompress/1 is used when the body *has* zlib headers and checksum
# unzip/1 works when the body has no headers or checksum.
unzipped =
try do
:zlib.uncompress(body)
rescue
ErlangError -> :zlib.unzip(body)
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone with greater knowledge of the deflate representation could probably pattern match on the start of the body binary to determine if it had the header and checksum, but that's beyond me... 😬

Comment on lines -714 to +741
|> Plug.Conn.put_resp_header("content-encoding", "deflate")
|> Plug.Conn.put_resp_header("content-encoding", non_existent_codec)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we actually support deflate, we can't use it as an example of an unknown compression codec. 😄

@s3cur3 s3cur3 marked this pull request as ready for review November 24, 2023 19:56
@wojtekmach
Copy link
Owner

yeah I'm happy to add it when someone actually needs but tbh I'm still unclear how exactly it should work. thanks for the PR though!

@wojtekmach wojtekmach closed this Nov 24, 2023
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 this pull request may close these issues.

2 participants