Skip to content

Instantly share code, notes, and snippets.

@theist
Created February 3, 2012 14:05
Show Gist options
  • Save theist/1730322 to your computer and use it in GitHub Desktop.
Save theist/1730322 to your computer and use it in GitHub Desktop.
redirect test script
url = ARGV.shift
redirect = true
while redirect do
redirect = false
status = ""
location = "<none>"
curl = `curl -s -I #{url}|dos2unix`
curl.each_line do |line|
if line =~ /HTTP\/1..\s+(\d+)/ then
status = $1
end
if line =~ /^Location:\s*(.*)/ then
location = $1
end
end
puts "#{url} -> #{status} -> #{location}"
if status =~ /3../ then
redirect = true
url = location
end
end
@theist
Copy link
Author

theist commented Feb 6, 2012

./foo.rb http://google.com
http://google.com -> 301 -> http://www.google.com/
http://www.google.com/ -> 302 -> http://www.google.es/
http://www.google.es/ -> 200 -> <none>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment