Created
June 29, 2011 16:39
-
-
Save rafaelss/1054268 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 "rubygems" | |
require "typhoeus" | |
require "awesome_print" | |
def run(follow) | |
request = Typhoeus::Request.new("http://www.google.com", :method => :get) | |
request.follow_location = follow | |
hydra = Typhoeus::Hydra.new | |
hydra.queue(request) | |
hydra.run | |
response = request.response | |
ap "follow location: #{follow}" | |
ap response.headers_hash | |
end | |
################## | |
ap "AFTER b8840c5" | |
run(false) | |
run(true) | |
################### | |
ap "BEFORE b8840c5" | |
module Typhoeus | |
class Response | |
def headers_hash | |
headers.split("\n").map {|o| o.strip}.inject({}) do |hash, o| | |
if o.empty? | |
hash | |
else | |
o = o.split(":") | |
hash[o.first.strip] = o.last ? o.last.strip : nil | |
hash | |
end | |
end | |
end | |
end | |
end | |
run(false) | |
run(true) |
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
$ ruby typhoeus_headers.rb | |
"AFTER b8840c5" | |
"follow location: false" | |
{ | |
"Location" => "http://www.google.com.br/", | |
"Cache-Control" => "private", | |
"Content-Type" => "text/html; charset=UTF-8", | |
"Set-Cookie" => "PREF=ID=e67e601bcb3fc662:FF=0:TM=1309365035:LM=1309365035:S=d90nwXjW6KthL-wJ; expires=Fri, 28-Jun-2013 16:30:35 GMT; path=/; domain=.google.com", | |
"Date" => "Wed, 29 Jun 2011 16:30:35 GMT", | |
"Server" => "gws", | |
"Content-Length" => "222", | |
"X-Xss-Protection" => "1; mode=block" | |
} | |
"follow location: true" | |
{ | |
"Location" => "http://www.google.com.br/", | |
"Cache-Control" => [ | |
[0] "private", | |
[1] "private, max-age=0" | |
], | |
"Content-Type" => [ | |
[0] "text/html; charset=UTF-8", | |
[1] "text/html; charset=ISO-8859-1" | |
], | |
"Set-Cookie" => [ | |
[0] "PREF=ID=2c66cb3d0cf225ea:FF=0:TM=1309365037:LM=1309365037:S=99q4Av29cJo5uetM; expires=Fri, 28-Jun-2013 16:30:37 GMT; path=/; domain=.google.com", | |
[1] "NID=48=KFHHKThDn2qEPOIgsTQANfAQi14af565bAZn0JVK3YgVWHQDNKoJjAjWX9EkrscTSuUrXgbycJ3JuF_HCnyqWkdWmumXkXHYfNSPuYZhfq9FdZ79ZH7ZEDbwKvkVHaA_; expires=Thu, 29-Dec-2011 16:30:37 GMT; path=/; domain=.google.com; HttpOnly", | |
[2] "PREF=ID=1725c9fb5ecbc8d5:FF=0:TM=1309365038:LM=1309365038:S=lM_sXhUl5r1K561i; expires=Fri, 28-Jun-2013 16:30:38 GMT; path=/; domain=.google.com.br", | |
[3] "NID=48=Br0VibZQhHJoQc5Znkg8Ew-UvBRUeyhKENHPUn7T5gYQ6-NWwJ7437FoqzkSCf9G2JeBpshEHFAVxBFqg_PGOorp3dmoox_CpakVnN8y5qOzYxxQ_azkROe9RZHlVWNA; expires=Thu, 29-Dec-2011 16:30:38 GMT; path=/; domain=.google.com.br; HttpOnly" | |
], | |
"Date" => [ | |
[0] "Wed, 29 Jun 2011 16:30:37 GMT", | |
[1] "Wed, 29 Jun 2011 16:30:38 GMT" | |
], | |
"Server" => [ | |
[0] "gws", | |
[1] "gws" | |
], | |
"Content-Length" => "222", | |
"X-Xss-Protection" => [ | |
[0] "1; mode=block", | |
[1] "1; mode=block" | |
], | |
"Expires" => "-1", | |
"Transfer-Encoding" => "chunked" | |
} | |
"BEFORE b8840c5" | |
"follow location: false" | |
{ | |
"HTTP/1.1 302 Found" => "HTTP/1.1 302 Found", | |
"Location" => "//www.google.com.br/", | |
"Cache-Control" => "private", | |
"Content-Type" => "text/html; charset=UTF-8", | |
"Set-Cookie" => "44 GMT; path=/; domain=.google.com", | |
"Date" => "44 GMT", | |
"Server" => "gws", | |
"Content-Length" => "222", | |
"X-XSS-Protection" => "1; mode=block" | |
} | |
"follow location: true" | |
{ | |
"HTTP/1.1 302 Found" => "HTTP/1.1 302 Found", | |
"Location" => "//www.google.com.br/", | |
"Cache-Control" => "private, max-age=0", | |
"Content-Type" => "text/html; charset=ISO-8859-1", | |
"Set-Cookie" => "00 GMT; path=/; domain=.google.com.br; HttpOnly", | |
"Date" => "00 GMT", | |
"Server" => "gws", | |
"Content-Length" => "222", | |
"X-XSS-Protection" => "1; mode=block", | |
"HTTP/1.1 200 OK" => "HTTP/1.1 200 OK", | |
"Expires" => "-1", | |
"Transfer-Encoding" => "chunked" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment