Make a HTTP header request with Curb
The -I/--head
option performs a HEAD
request. With libcurl C API you need to set the CURLOPT_NOBODY option.
With curb, you can set this option on your handle as follow:
h = Curl::Easy.new("http://www.google.com")h.set :nobody, trueh.performputs h.header_str# HTTP/1.1 302 Found# Location: http://www.google.fr/# Cache-Control: private# Content-Type: text/html; charset=UTF-8# ...
As an alternative, you can use one of the convenient shortcut like:
h = Curl::Easy.new("http://www.google.com")# This sets the option behind the scenes, and call `perform`h.http_headputs h.header_str# ...
Or like this one, using the class method:
h = Curl::Easy.http_head("http://www.google.com")puts h.header_str# ...
Note: the ultimate shortcut is Curl.head("http://www.google.com")
. That being said wait until the next curb release before using it, since it's NOT working at the time of writing, and has just been patched: see this pull request.