Skip to content
instance method

Net::HTTPSession#head

head(path, initheader = nil)

Sends a HEAD request to the server; returns an instance of a subclass of Net::HTTPResponse.

The request is based on the Net::HTTP::Head object created from string path and initial headers hash initheader:

Example
res = http.head('/todos/1') # => #<Net::HTTPOK 200 OK readbody=true>
res.body                    # => nil
res.to_hash.take(3)
# =>
[["date", ["Wed, 15 Feb 2023 15:25:42 GMT"]],
 ["content-type", ["application/json; charset=utf-8"]],
 ["connection", ["close"]]]
See also #get #inspect #finish #ipaddr also in 4.1 · 3.4