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

un-gzip based on content-encoding #81

Open
matthusby opened this issue Oct 10, 2015 · 4 comments
Open

un-gzip based on content-encoding #81

matthusby opened this issue Oct 10, 2015 · 4 comments

Comments

@matthusby
Copy link
Contributor

@matthusby matthusby commented Oct 10, 2015

If the response has Content-Encoding: gzip the body should be automatically unzipped.

@edgurgel
Copy link
Owner

@edgurgel edgurgel commented Nov 2, 2015

This will be done upstream by hackney: benoitc/hackney#155

We can keep this issue open until it's available.

Loading

@marvelm
Copy link

@marvelm marvelm commented May 18, 2016

For anyone looking for a stopgap until this feature is implemented:

res = HTTPoison.get(url)
gzipped = Enum.any?(res.headers, fn (kv) ->
  case kv do
    {"Content-Encoding", "gzip"} -> true
    {"Content-Encoding", "x-gzip"} -> true
    _ -> false
  end
end)

# body is an Elixir string
body = if gzipped do
    :zlib.gunzip(res.body)
  else
    res.body
  end

Loading

@jaimeiniesta
Copy link

@jaimeiniesta jaimeiniesta commented May 11, 2017

@marvelm works like a charm thanks - but some servers return { "Content-Encoding", "x-gzip" } instead.

Loading

@setharnold
Copy link

@setharnold setharnold commented Feb 11, 2020

If someone gets around to implementing this, it might also be worth implementing support for brotli as well; it's supported in both Firefox and Chromium so is likely to be supported by more servers over time.

Thanks

Loading

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

Successfully merging a pull request may close this issue.

None yet
5 participants