-
Notifications
You must be signed in to change notification settings - Fork 961
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
GZip content not automatically being deflated #562
Comments
What version of ruby and httparty are you using? GZip should be handled by net/http. HTTParty removed its decompression logic because of this. Any of that trigger some thoughts on your end? |
Seeing exactly the same issue.
FYI, if you remove the header i.e. require 'createsend'
AUTH = { api_key: ENV['API_KEY'] }
client_id = ENV['CLIENT_ID']
client = CreateSend::Client.new AUTH, client_id
response = client.send(:get, 'campaigns')
response.body => # Still GZipped content
request = response.request
request.options.merge!(headers: request.options[:headers].tap { |h| h.delete "Accept-Encoding" })
request.perform.response.body => # Unzipped content Could it be a Campaign Monitor problem, perhaps? Not well-versed enough in this stuff to know. |
@jnunemaker I think @jackross is right. This seems to be an issue with Create Send probably shouldn't be handling the compression since For the record here is my version info: ruby: 2.4.1 I will leave this issue open for you to determine if it should be closed since I am not entirely sure. |
Hello @jackross, My Ruby and Createsend Gem version as below:
I could not reproduce the issue due to identical response body received with the code you provided, here are my code and the output: require 'createsend'
AUTH = { api_key: ENV['API_KEY'] }
client_id = ENV['CLIENT_ID']
client = CreateSend::Client.new AUTH, client_id
response = client.send(:get, 'lists')
p"response.body.encoding: #{response.body.encoding}" # UTF-8
p"response.body: #{response.body}" # [{\"ListID\":\"12345679\",\"Name\":\"test\"}]
request = response.request
request.options.merge!(headers: request.options[:headers].tap { |h| h.delete "Accept-Encoding" })
request.perform.response.body
p"request.perform.response.body.encoding: #{request.perform.response.body.encoding}" # UTF-8
p"request.perform.response.body: #{request.perform.response.body}" # [{\"ListID\":\"12345679\",\"Name\":\"test\"}] Can you please double check? |
@liu33173847 The response from Createsend has to be over 1KB. I forgot to mention that in my issue. I have updated it now. |
Hello @KNejad, We have merged the change for removing "Accept-Encoding"=>"gzip, deflate" and released it now for version 4.1.2 (https://rubygems.org/gems/createsend). Please kindly check and verify if it solved the issue. |
Removing I think this is still a problem with HTTParty. I can reproduce it on ruby 2.4 and httparty 0.15.6. |
I am definitely seeing this on 2.4 with the examples provided. When I add handle_deflation back it fixes the problem so I am inclined to do that. I'll try to get a failing spec and PR soon. fyi @jaypatrickhoward |
I am experienceing this with ruby 2.3 and httparty v 0.16.2. But I am lost a bit here... what is the recommended solution for deflation? |
Still running into this issue. Not just with CreateSend, but also Azure APIM will not be un-zipped correctly when you send the request with @dvodvo If you DONT send the 'Accept-Encoding', header then it DOES work correctly and is gzipped. |
Also just had this issue. |
I'm running into this issue as well. When rolling back all the way to 0.14.0 I do not run into this problem. Httparty 0.16.3 and ruby 2.5.1 |
Okay. Here is what is happening.
But if you do ruby assumes that you want to decode response yourself and does nothing. It's counter intuitive, confusing and not user friendly. |
@TheSmartnik Go with your gut. It isn't super clear to me how many people are having problems with how it currently works verse how many people would have problems if we changed it. Any sense how much of an impact this would be? I'm assuming a minor version change for sure. Is that right? I'm all for user friendly. |
It could just be a judgement call of how many people are likely adding Or not changing the behavior and finding another way of mitigating the incorrect usage, documentation doesn't help much as people only find docs when they're looking, so would a warning at runtime or something obviously visible in logs or debugger reach these people better? |
@BookOfGreg Yeah, I was thinking about warning at first. However, if header is set intentionally, it would be annoying for users as they got no way to get rid of it |
Since I re-opened the issue, maybe I should chime in. I am not sure what correct behaviour would be either. However, the documentation aspect did leave me 'wanting'. Usually, the base usage has examples and those, to me, are the best starting points. If that were to illustrate in particular major gotchas, this type of issue would go away. The number of major gotchas is what would limit the effectiveness of this tactic. |
I'm no longer on the project where I was experiencing this issue, but, if I'm understanding the discussion correctly, here's my two cents: Make it work "out of the box" for people who are using the headers intentionally and correctly. That is, no special flags need to be passed, etc. Create a flag that can be passed to signal "workaround mode". This will be used by those who have to accommodate broken server behavior. |
Since rest-client 2.1, the gzip behaviour has changed rest-client/rest-client#597 such that it relies on Net::HTTP rather than performing the decompression itself. This test is currently failing because the body is not getting decoded correctly, and I can't find a way of getting it to pass. It's blocking us from adding new features so I thought it would be reasonable to temporarily comment it out and I'll write up a card for Platform Health to investigate putting it back. I'm not sure if the test is actually useful in the first place because we're testing HTTP behaviour of the Gem, not anything in our code. I've tried the following things to get it to work: - Manually adding an `Accept-Encoding` header (although it seems like this definitely shouldn't work: jnunemaker/httparty#562 (comment)) - Manually adding a `Content-Type` header. - Generating the Gziped string with `GzipWriter`. One thing I've noticed is that for some reason `decode_content` is always set to false on the Net::HTTPResponse object (https://ruby-doc.org/stdlib-2.6.3/libdoc/net/http/rdoc/Net/HTTPResponse.html).
I've just been doing a bit of testing and found that if any headers are supplied then the Accept-Encoding headers are being removed. Tested using https://lumtest.com/echo.json which returns the headers sent with a request. If I specify no headers it sends the Accept-Encoding headers, if I specify any others in the |
So, I'm one of those poor schmucks who was setting As I understand it, here are the 3 cases. CAVEAT: I have NOT tested all these yet, just trying to first recap what I'm reading in the thread. Here is a summary of the behavior as of HTTParty v0.18.1 Case 1: No headers set in HTTParty
Case 2:
Case 3: Other headers set in HTTParty
|
I've raised a PR to fix this issue: #729 |
Better handling of Accept-Encoding / Content-Encoding decompression (fixes #562)
I am facing the same issue on httparty 0.16.4. I found it could be workaround by adding a header if @raw_request.respond_to?(:decode_content) && (headers_hash.key?('Accept-Encoding') || headers_hash.key?('accept-encoding'))
# Using the '[]=' sets decode_content to false
@raw_request['accept-encoding'] = @raw_request['accept-encoding']
end |
@Zhen-w you should upgrade to at least httparty 0.19.0 to get the proper fix for this. In order versions the behavior was plainly wrong/counterintuitive. |
I tried, but it's a quite big effort for us to upgrade the lib since our infra lib depends on the version. |
When making a HTTParty GZipped request with
Accept-Encoding
set togzip, deflate
I would expect HTTParty to automatically un-GZip the response. What I am seeing is content which is still GZipped.To reproduce
Create HTTParty get request with
Accept-Encoding
set togzip, deflate
as belowExpected result
This is related to post I created on campaignmonitor/createsend-ruby#58 where they are doing the above.
Edit: The response body has to be over 1KB for the compressions to kick in. Which is where the bug appears
The text was updated successfully, but these errors were encountered: