title: How to get HTTP headers before downloading with Ruby's OpenUri
body: <p>I am currently using OpenURI to download a file in Ruby.  Unfortunately, it seems impossible to get the HTTP headers without downloading the full file:</p>
  
  <pre><code>open(base_url,
    :content_length_proc =&gt; lambda {|t|
      if t &amp;&amp; 0 &lt; t
        pbar = ProgressBar.create(:total =&gt; t)
    end
    },
    :progress_proc =&gt; lambda {|s|
      pbar.progress = s if pbar
    }) {|io|
      puts io.size
      puts io.meta['content-disposition']
    }
  </code></pre>
  
  <p>Running the code above shows that it first downloads the full file and only then prints the header I need.</p>
  
  <p>Is there a way to get the headers before the full file is downloaded, so I can cancel the download if the headers are not what I expect them to be?</p>