Giter Club home page Giter Club logo

Comments (4)

zedalaye avatar zedalaye commented on August 16, 2024

This issue may be related to ZLib/GZip. Not sure. The workaround is to ask RestClient to send "Accept-Encoding: identity" header instead of its default "Accept-Encoding: gzip, deflate"

from mailjet-gem.

zedalaye avatar zedalaye commented on August 16, 2024

I traced this issue into RestClient::Request#decode. I dumped the "body" param to a base64 string and I used it to check whether the problem is in RestClient, Ruby, ZLib or MailJet v3 API.

To dump the "body" buffer I used RubyMine debugger, used the "Evaluate Expression" function and I evaluated Base64.strict_encode64(body)

The resulting string is : H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA=

Then I wrote this very simple program :

require 'base64'
require 'zlib'
require 'stringio'

puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "ZLib version: #{Zlib.zlib_version}"

DATA = "H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA="

puts "\nBase64 string\n#{DATA}\n"

buffer = Base64.strict_decode64(DATA)

puts "\nRaw buffer\n#{buffer}\n\n"

gz = Zlib::GzipReader.new(StringIO.new(buffer))

begin
  puts "\nZlib::GzipReader.new(StringIO.new(buffer)).read"
  puts gz.read
rescue Exception => e
  puts e
end

puts "\nZlib::GzipReader.new(StringIO.new(buffer)).read(77)"
puts gz.read(77)

puts "\nUsing Unix tools (base64 + gunzip)"
puts `echo #{DATA} | base64 --decode | gunzip -c - 2>&1`

Which outputs :

RUBY_VERSION: 2.1.2
ZLib version: 1.2.8

Base64 string
H4sIAAAAAAAAA6pWUHItKsov8sxLy1dSsFJQUtKBivimFhcnpqeCBf2TslKTSxTy8ksU0vJL81JAioJLEktKi53zU8BKTAxMFGoBAAA=

Raw buffer
���VPr-*�/��K�WR�RPRҁ�����'������R�K���K���K�R@��K�KJ���S�JL
                                                            L�j�


Zlib::GzipReader.new(StringIO.new(buffer)).read
unexpected end of file

Zlib::GzipReader.new(StringIO.new(buffer)).read(77)
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }

Using Unix tools (base64 + gunzip)
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }
gzip: stdin: unexpected end of file

So I suspect the MailJet server to return invalid GZip encoded data but at the same time, the same request run with curl works as expected :

curl -s -X GET --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" https://api.mailjet.com/v3/REST/contactslist/42
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }

But the same request with wget never output anything (nor print any error message) 👍

wget -d --http-user $MJ_APIKEY_PUBLIC --http-password=$MJ_APIKEY_PRIVATE -O result.json --header "Accept: application/json" --header "Accept-Encoding: gzip" https://api.mailjet.com/v3/REST/contactslist/42

The result.json file remains empty.

from mailjet-gem.

zedalaye avatar zedalaye commented on August 16, 2024

I made another change to the Mailjet::Resource code to force deflate encoding instead of gzip and it works like a charm ! (I'll push these changes to my fork for those interrested)

from mailjet-gem.

tylerjnap avatar tylerjnap commented on August 16, 2024

Fixed!

from mailjet-gem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.