R – How to request for gzipped pages from web servers through ruby scripts

compressiongziphttpruby

I have a ruby script that goes and saves web pages from various sites, how do i make sure that it checks if the server can send gzipped files and saves them if available…
any help would be great!

Best Answer

One can send custom headers as hashes ...

custom_request = Net::HTTP::Get.new(url.path, {"Accept-Encoding" => "gzip"})

you can then check the response by defining a response object as :

response = Net::HTTP.new(url.host, url.port).start do |http| 
http.request(custom_request) 
end 

p [response['Content-Encoding']

Thanks to those who responded...