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

Monkey patch for Ruby 2.0 and gzip response + gem 'right_aws' #473

Closed
jinixdme opened this issue Oct 21, 2013 · 1 comment
Closed

Monkey patch for Ruby 2.0 and gzip response + gem 'right_aws' #473

jinixdme opened this issue Oct 21, 2013 · 1 comment

Comments

@jinixdme
Copy link

If using gem 'right_aws' v3.1.0 side-by-side with Twitter gem 4.8.1 and Ruby 2.0 I got the following error for a status call:
"unexpected token at '\x1F\x8B\b' ...gems/json-1.8.1/lib/json/common.rb:155:in 'parse'"

Inspired by flexera-public/right_aws#167 I wrote a little monkey patch for Twitter to work with Ruby 2.0 + gzip response.

module Twitter
  module Response
    class ParseJson < Faraday::Response::Middleware

      def on_complete(env)
        if respond_to?(:parse)
          if env[:response_headers]['content-encoding'].include?("gzip")
            # PATCH for zipped data
            body = StringIO.new(env[:body])
            string = Zlib::GzipReader.new(body).read
            env[:body] = parse(string) unless [204, 301, 302, 304].include?(env[:status])
          else
            # default
            env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
          end
        end
      end

    end
  end
end

Hope this helps. Maybe it's just a 'aws_right' issue, because without this gem everything works fine...

tilljoel pushed a commit to tilljoel/bs that referenced this issue Nov 4, 2013
Ruby 2.0.0 does not automatically gunzip the net/http response, a
possible solution is:

sferik/twitter-ruby#473
tilljoel added a commit to tilljoel/bs that referenced this issue Nov 4, 2013
Ruby 2.0.0 does not automatically gunzip the net/http response, a
possible solution is:

sferik/twitter-ruby#473
@sferik
Copy link
Owner

sferik commented Nov 18, 2013

As far as I can tell, this is an issue with right_aws, not this library.

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