Skip to content

Instantly share code, notes, and snippets.

@timshadel
Created December 1, 2009 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timshadel/246482 to your computer and use it in GitHub Desktop.
Save timshadel/246482 to your computer and use it in GitHub Desktop.
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