Created
May 24, 2011 00:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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