Question

According to the Compression section of the documentation of Net::HTTP, it should automatically uncompress compressed responses. However, when I tried with a number of JSON requests with different servers, I am not getting automatic decompression.

require 'net/http'
uri = URI("http://yourhost.com")
http = Net::HTTP.new(uri.host, uri.port)
res = http.get(uri.request_uri)
Was it helpful?

Solution

The issue was being caused by right_http_connection gem which is in my bundle. The following gives proper decoded response in IRB.

require 'net/http'
require 'uri'
uri = URI("http://vimeo.com/api/oembed.json?url=http://vimeo.com/69655841&width=150")
http = Net::HTTP.new(uri.host, uri.port)
res = http.get(uri.request_uri)
res.body

However, requiring right_http_connection starts giving a gzipped response.

require 'net/http'
require 'uri'
require 'right_http_connection'
uri = URI("http://vimeo.com/api/oembed.json?url=http://vimeo.com/69655841&width=150")
http = Net::HTTP.new(uri.host, uri.port)
res = http.get(uri.request_uri)
res.body

This is a known issue and its fix has already been merged but a newer gem version containing the fix has not been released.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top