Created
December 1, 2009 17:46
-
-
Save timshadel/246482 to your computer and use it in GitHub Desktop.
This file contains 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
require 'restclient' | |
require 'pp' | |
require 'hpricot' | |
if ARGV.size == 0 | |
puts "Usage: showheaders.rb <url> [headers]" | |
puts | |
puts " Headers are optional, but should come in as pairs of arguments." | |
puts " showheaders.rb <url> If-None-Match 4eb6dc" | |
exit 1 | |
end | |
url = ARGV[0] | |
headers = {} | |
(1..ARGV.size-1).step(2) do |i| | |
headers[ARGV[i]] = ARGV[i+1] | |
end | |
response = nil | |
begin | |
response = RestClient.get url, headers | |
rescue RestClient::ExceptionWithResponse => e | |
response = e.response | |
def response.headers | |
RestClient::Response.beautify_headers(self.to_hash) | |
end | |
end | |
puts response.code | |
pp response.headers | |
pp Hpricot(response.to_s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment