Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Net::HTTP#head

head(path, initheader = nil)

Gets only the header from path on the connected-to host. header is a Hash like { ‘Accept’ => ‘/’, … }.

This method returns a Net::HTTPResponse object.

This method never raises an exception.

Example
response = nil
Net::HTTP.start('some.www.server', 80) {|http|
  response = http.head('/index.html')
}
p response['content-type']
See also #get #inspect #finish #ipaddr also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0