wrest icon indicating copy to clipboard operation
wrest copied to clipboard

Add gzip support

Open kaiwren opened this issue 14 years ago • 8 comments

kaiwren avatar Aug 23 '10 06:08 kaiwren

It seems Net/HTTP in Ruby 1.9 handles compression transparently.

The docs are at http://ruby-doc.org/ruby-1.9/classes/Net/HTTP.html

The patch that does it is at http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/12693

jasim avatar Dec 27 '10 08:12 jasim

Net/HTTP Ruby 1.9 : Compression is enabled only when the Get method is called. Wrest uses the Request method for fine grained control.

  • For Get requests, we can direct Wrest to use the Net::HTTP.Get function directly. This would take care of compression. I am not sure of the trade-offs for this approach.
  • Or we can write the custom GZip code ourselves - but this would entail duplicating stuff that Net::HTTP provides.

jasim avatar Dec 27 '10 09:12 jasim

Ref: http://stackapps.com/questions/1330/get-user-data-using-curb-in-ruby

The StackOverflow URL given in the below code snippet always return gzip encoded response (irrespective of whether 'accept-encoding: gzip' is specified or not)

require 'net/http'
require 'uri'

url = URI.parse("http://api.stackoverflow.com")
res = Net::HTTP.start(url.host, url.port) {|http|
  http.get('/1.0/users/231917?type=jsontext')
}
puts res.body

Running the above in Ruby 1.8 would produce a binary gzip output - which we have to manually unzip.

However Ruby 1.9 transparently unzips the content and presents the actual json.

jasim avatar Dec 27 '10 11:12 jasim

Allow auto unzipping to be the default, but ensure this can be controlled by a flag in Request options in case somebody actually wants the binary output. We'll also need a functional test for this, and a spike with libcurl. Feel free to create more tickets as needed.

This means we'll have to implement unzipping on 1.8.7. See ActiveSupport::OrderedHash for an example of a feature that exists on 1.9 and is implemented only on 1.8.x

kaiwren avatar Jan 02 '11 14:01 kaiwren

I'm wondering whether there is a use case for directly obtaining the zip without decompression. There is 'content-disposition: attachment' to send/receive zip files.

jasim avatar Jan 03 '11 10:01 jasim

Transparently decompressing would be hard/unwieldy. Ruby 1.9 has added method Net::HTTP:Response.body= to enable changing the body (to specifically facilitate decompressing). Ruby 1.8 does not have the function.

jasim avatar Jan 03 '11 12:01 jasim

Is this done? I could use it for http://www.salesforce.com/us/developer/docs/api_rest/Content/intro_rest_compression.htm

It probably also needs documentation and an easy way to turn it on and off both globally and per request.

kaiwren avatar Apr 06 '11 14:04 kaiwren

Is this done? I could use it for http://www.salesforce.com/us/developer/docs/api_rest/Content/intro_rest_compression.htm

It probably also needs documentation and an easy way to turn it on and off both globally and per request.

kaiwren avatar Apr 06 '11 14:04 kaiwren