Compression

igrigorik edited this page Jan 31, 2011 · 1 revision

If the upstream server can compress (gzip or deflate) the response, then em-http can transparently decode the data for you. To make this work, simply indicate to the upstream server that you will accept compressed data, and em-http will do the rest:

EventMachine.run do
  http = EventMachine::HttpRequest.new('http://website.com/gzip').get :head => {"accept-encoding" => "gzip, compressed"}

  http.callback {
      http.response_header["CONTENT_ENCODING"] # => "gzip"
      http.response # => uncompressed data
  }
end