How to get HTTP headers before downloading with Ruby's OpenUri -


i using openuri download file in ruby. unfortunately, seems impossible http headers without downloading full file:

open(base_url,   :content_length_proc => lambda {|t|     if t && 0 < t       pbar = progressbar.create(:total => t)   end   },   :progress_proc => lambda {|s|     pbar.progress = s if pbar   }) {|io|     puts io.size     puts io.meta['content-disposition']   } 

running code above shows first downloads full file , prints header need.

is there way headers before full file downloaded, can cancel download if headers not expect them be?

you can use net::http matter, example:

require 'net/http'  http = net::http.start('stackoverflow.com')  resp = http.head('/') resp.each { |k, v| puts "#{k}: #{v}" } http.finish 

another example, time getting header of wonderful book, object orient programming ansi-c:

require 'net/http'  http = net::http.start('www.planetpdf.com')  resp = http.head('/codecuts/pdfs/ooc.pdf') resp.each { |k, v| puts "#{k}: #{v}" } http.finish 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -