wrest
wrest copied to clipboard
Add gzip support
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
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.
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.
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
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.
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.
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.
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.