-
Notifications
You must be signed in to change notification settings - Fork 117
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
:zlib.inflate_nif/4
error with deflate-encoded resource
#215
Comments
Thank you for the report. The problem is we're using :zlib.unzip/1 for deflate: https://github.com/wojtekmach/req/blob/v0.3.11/lib/req/steps.ex#L871 however it seems we should use iex> Req.get!("http://localhost:8000/deflate", raw: true).body |> :zlib.uncompress()
"{\n \"deflated\": true, \n \"headers\": {\n \"Accept-Encoding\": \"zstd, br, gzip, deflate\", \n \"Host\": \"localhost:8000\", \n \"User-Agent\": \"req/0.3.11\"\n }, \n \"method\": \"GET\", \n \"origin\": \"172.17.0.1\"\n}\n" I'm a bit lost which content-encoding header value should correspond to which :zlib functions so any links to definite references would be very helpful. |
Not sure either, but for "deflate", |
Looks like Tesla has the same issue:
localhost:8000 is httpbin running with Docker. |
Tesla uses `httpc` by default, IIRC
Le jeu. 10 août 2023, 18:15, Wojtek Mach ***@***.***> a
écrit :
… Looks like Tesla has the same issue:
iex> Mix.install([:tesla])
iex> Tesla.client([Tesla.Middleware.DecompressResponse]) |> Tesla.get("http://localhost:8000/deflate")
** (ErlangError) Erlang error: :data_error
(erts 14.0.2) :zlib.inflate_nif(#Reference<0.2165264108.559022081.244095>, 8192, 16384, 0)
(erts 14.0.2) :zlib.dequeue_all_chunks_1/3
(erts 14.0.2) :zlib.inflate/3
(erts 14.0.2) :zlib.unzip/1
(tesla 1.7.0) lib/tesla/middleware/compression.ex:65: Tesla.Middleware.Compression.decompress/1
(tesla 1.7.0) lib/tesla/middleware/compression.ex:60: Tesla.Middleware.Compression.decompress/1
iex:16: (file)
localhost:8000 is httpbin running with Docker.
—
Reply to this email directly, view it on GitHub
<#215 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPQAO6ZEKJJ26ZYU2AXQKLXUUCJBANCNFSM6AAAAAA3LBUGQE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
It does. Why? |
Thinking out loud, sorry, it doesn't matter actually as the compression is handled by Tesla. |
@dorian-marchal I decided to just remove support for deflate. If it's a blocker for you to adopt Req, please let me know. There's a pretty funny/tragic history about it pasted below. Given the confusion and that support varies (or, you know, varied like 10-15 years ago and a bunch of people decided to drop it too) I don't want to deal with it unless there are actual use cases for this. Per https://zlib.net/zlib_faq.html#faq39 What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? "gzip" is the gzip format, and "deflate" is the zlib format. They should probably have called the second one "zlib" instead to avoid confusion with the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 correctly points to the zlib specification in RFC 1950 for the "deflate" transfer encoding, there have been reports of servers and browsers that incorrectly produce or expect raw deflate data per the deflate specification in RFC 1951, most notably Microsoft. So even though the "deflate" transfer encoding using the zlib format would be the more efficient approach (and in fact exactly what the zlib format was designed for), using the "gzip" transfer encoding is probably more reliable due to an unfortunate choice of name on the part of the HTTP 1.1 authors. Bottom line: use the gzip format for HTTP 1.1 encoding. |
OK, RFC 9110 § 8.4.1.2 says:
(emphasis mine) so yeah, it is well specified after all, we can bring back the support if someone really needs it. |
Hello, when fetching deflate-encoded content,
Req
fails to decode it:It appears that there is a decoding issue for deflate-encoded content.
HTTPoison
seems to be able to decode it:It seems to work with
Finch
, too:Note: if httpbin.org is down, one can test with kennethreitz/httpbin docker image.
The text was updated successfully, but these errors were encountered: