Zip header : HTTP Reponse « Network « Ruby

Zip header

require 'net/http'
require 'uri'

module Net
  class HTTP
    def HTTP.get_with_headers(uri, headers=nil)
      uri = URI.parse(uri) if uri.respond_to? :to_str
      start(, uri.port) do |http|
        path_query = uri.path + (uri.query ? ('?' + uri.query) : '')
        return http.get(path_query, headers)

gzipped = Net::HTTP.get_with_headers('',
                                     {'Accept-Encoding' => 'gzip'})
puts gzipped['Content-Encoding']
puts gzipped.body.size


Related examples in the same category

1.Checking for Errors and Redirects
2.Grabbing the Contents of a Web Page.rb
3.Get response encoding and body
4.Get url and response
5.Get response code
6.get server information from the response
7.Each key in the response
8.For each segment received
9.Read mysql command output
10.Read a web page