-
Notifications
You must be signed in to change notification settings - Fork 66
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 gzip decompressing in Ruby gem #325
base: main
Are you sure you want to change the base?
Conversation
Contributor License Agreement Instructions Please download the appropriate CLA below. Once downloaded, please read, sign, and send back to us at [email protected]. Please note, this account is not monitored so please visit https://mailchimp.com/contact/ if you need support. Individual CLA: Mailchimp Individual CLA Once you’ve emailed us the signed CLA, please reply here (e.g. CLA signed and sent!) and we’ll verify it. What to do if you already signed the CLA |
CLA signed and sent! |
As a note, I accidentally sent the CLA from an incorrect email. I've resent it from my personal email. |
This commit sets the middleware used by Excon connections to include the defaults and Excon::Middleware::Decompress, which decompresses gzip data returned from the Mailchimp API.
3982c5b
to
b6111df
Compare
Contributor License Agreement Instructions Please download the appropriate CLA below. Once downloaded, please read, sign, and send back to us at [email protected]. Please note, this account is not monitored so please visit https://mailchimp.com/contact/ if you need support. Individual CLA: Mailchimp Individual CLA Once you’ve emailed us the signed CLA, please reply here (e.g. CLA signed and sent!) and we’ll verify it. What to do if you already signed the CLA |
:read_timeout => @read_timeout, | ||
:write_timeout => @write_timeout, | ||
:connect_timeout => @connect_timeout, | ||
:middlewares => [Excon.defaults[:middlewares], Excon::Middleware::Decompress].flatten) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the magic line. It sets the middlewares used by the new Excon connection to be the defaults (Excon.defaults[:middlewares]
) and Excon::Middleware::Decompress
, which knows how to decompress gzip response data.
Hey @dhughes thanks for opening this PR! We believe this issue may have been due to a configuration issue on our end, which has been fixed. Would you mind seeing if you're still seeing the encoding issues outside of this fix? |
This is happening on us17 for us, but only when calling |
Description
I use the Mailchimp Marketing Ruby gem in two integration projects that sync information from two ecommerce platforms to Mailchimp. I recently noticed a spike in errors with a message of "illegal/malformed utf-8" while parsing JSON data.
Keeping a long story short, what I learned is that was apparently only occurring on the
us18
server and only within Ruby.I was able to use Postman to make the same request to us17 and us18 without any problems. However, when using the Mailchimp marketing gem, I'd run into the problem.
I've narrowed the problem down to the gem not being able to handle gzip data, and us18 only returning gzip data.
Here's an example that should reproduce the problem. This assumes you have the gem installed.
Please note that I've intentionally provided bad
customer_params
. I've been seeing the issue specifically with error responses, though maybe it occurs with successes too. I'm using theadd_store_customer
method, since that's where I was running into the problem.Now, call this method with a valid access token for a user on a server other than
us18
. You should see output like this:This should output something like:
Next, call this same method for a user on
us18
:This should output something like:
That weird response body is gzip data that the Excon HTTP library doesn't know what to do with.
I tried various approaches to addressing this, but the only one I found that worked was to use the
Excon::Middleware::Decompress
middleware. This recognizes gzip responses and decodes them.If you pull my PR, regenerate and install the gem, running both of the examples above will produce the expected output.
With regards to this PR, I looked to see if there was a useful way to add a test for this, but wasn't able to find one. If you require a test for this PR, please let me know what you're looking for and I'll take care of it.
Known Issues