Created
February 17, 2012 17:34
-
-
Save lukesmith/1854513 to your computer and use it in GitHub Desktop.
url-tester
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 'csv' | |
require 'net/http' | |
require 'rainbow' | |
require 'uri' | |
csv = 'mycsv.csv' | |
@host_port = 'http://localhost:9292' | |
def make_request(url_path) | |
url = URI.parse(URI.escape(@host_port + url_path)) | |
found = false | |
until found | |
puts " making request to #{url}" | |
host, port = url.host, url.port if url.host && url.port | |
req = Net::HTTP::Head.new(url.path) | |
res = Net::HTTP.start(host, port) {|http| http.request(req) } | |
res.header['location'] ? url = URI.parse(res.header['location']) : found = true | |
unless url.host == 'localhost' | |
found = true | |
end | |
end | |
res | |
end | |
CSV.foreach(csv) do |row| | |
url_path = row[0] | |
puts "Checking #{@host_port}#{url_path}" | |
res = make_request(url_path) | |
acceptable_codes = ['200', '303'] | |
unless acceptable_codes.include?(res.code) | |
puts " #{res.code} - #{@host_port}#{url_path}".color(:red).bright | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment