How do I get Ruby's Net::HTTP module to cancel a request?
The call to http.finish 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.
EDIT: I want to avoid making a HEAD request. So, make a get request, unless content-type is html, cancel the request.
Thanks!
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