Skip to content

Instantly share code, notes, and snippets.

@boscomonkey
Created May 24, 2011 00:02
Show Gist options
  • Save boscomonkey/987908 to your computer and use it in GitHub Desktop.
Save boscomonkey/987908 to your computer and use it in GitHub Desktop.
Perform an HTTP HEAD on an URL. Returns a Net::HTTPResponse object to access the status code and headers.
class GetHead
# Returns a Net::HTTPResponse. Get the status code (as string):
# resp = with_http "http://imaiku.me/"
# code = resp.code # => "301"
# resp.each {|k,v| puts k + "\t" + v}
def with_http url
uri = URI.parse url
http = Net::HTTP.start uri.host, uri.port
resp = http.head uri.path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment