Buck Shlegeris Buck Shlegeris - 11 months ago 72
Ruby Question

Net::HTTP failing on a head request

I'm trying to make an HTTP Head request using Net::HTTP.

require 'net/http'

uri = URI("https://github.com/rails/rails")
http = Net::HTTP.new(uri.host, uri.port)
request = http.head(uri)

puts request


AFAICT, this is because Net::HTTP is waiting on a response body which will never come. How do I ask Net::HTTP to make a request and not wait on the response body?


If you follow the documentation properly, it works just fine. The library implementation probably has some assumptions on the usage when it determines whether to read the payload.

response = nil
Net::HTTP.start('github.com', :use_ssl => true) do |http|
  response = http.head('/rails/rails')

response.each { |k, v| [k, v] }