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

HTTParty response body returning compressed GZipped data #777

Open
jaypinho opened this issue Feb 3, 2023 · 1 comment
Open

HTTParty response body returning compressed GZipped data #777

jaypinho opened this issue Feb 3, 2023 · 1 comment

Comments

@jaypinho
Copy link

jaypinho commented Feb 3, 2023

Using Ruby 3.0.4 and httparty 0.20.0

Here's an example API call:

db_call = HTTParty.patch("https://[MYSUBDOMAIN].supabase.co/rest/v1/streets?street_name=Main", headers: {
    "apikey": ENV['SUPABASE_SECRET_KEY'],
    "Authorization": "Bearer #{ENV['SUPABASE_SECRET_KEY']}",
    "Content-Type": "application/json",
    "Prefer": "return=representation"
  }, body: JSON.generate({"street_id": 12345})

puts db_call.response.body # Prints a bunch of gzipped gibberish
sio = StringIO.new( db_call.response.body )
gz = Zlib::GzipReader.new( sio )
puts gz.read() # Prints the actual content

My understanding from the docs is that HTTParty automatically uncompresses gzipped responses as long as I don't explicitly specify an Accept-Encoding request header.

Why is that not happening here?

P.S. FWIW, I just tried a very similar HTTParty POST call (rather than PATCH) and the response came back uncompressed as expected.

@jason-o-matic
Copy link

I've run into this for a GET request. In my case the response includes a Range header, which causes Net::HTTP to not un-gzip the response automatically. Ideally I think HTTParty would automatically handle decompression of gzip data when Net::HTTP didn't handle it.

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