title: How to cancel Ruby Net::HTTP request?
body: <p>How do I get Ruby's Net::HTTP module to cancel a request?</p>
  
  <p>The call to <code>http.finish</code> below raises an error. I get the impression that the response object doesn't know that the connection was closed and still expects more data.</p>
  
  <p>I want to avoid making a HEAD request. So, make a GET request, unless content-type is HTML, cancel the request.</p>
  
  <pre><code>Net::HTTP.start(uri.host, uri.port) do |http|
    http.request_get(uri.path) do |response|
      unless response['content-type'] =~ /html/i
        http.finish
      end
    end
  end
  
  /usr/lib/ruby/1.8/net/http.rb:2241:in `stream_check': attempt to read body out of block (IOError)
      from /usr/lib/ruby/1.8/net/http.rb:2171:in `read_body'
      from /usr/lib/ruby/1.8/net/http.rb:2198:in `body'
      from /usr/lib/ruby/1.8/net/http.rb:2137:in `reading_body'
      from /usr/lib/ruby/1.8/net/http.rb:1052:in `request'
      from /usr/lib/ruby/1.8/net/http.rb:948:in `request_get'
      from net.rb:9
      from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
      from /usr/lib/ruby/1.8/net/http.rb:440:in `start'
      from net.rb:7
  </code></pre>