-
Notifications
You must be signed in to change notification settings - Fork 72
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
Exception thrown when trying to find an inexisting resource #26
Comments
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" |
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 The resulting string is : 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 :
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. |
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) |
RestClient::ResourceNotFound exceptions are handled by Mailjet::Connection and turned into Mailjet::ApiError exceptions
Fixed! |
Instead of returning nil, raises an "unexpected end of file" exception
The text was updated successfully, but these errors were encountered: