Last active
December 19, 2015 18:49
-
-
Save OriPekelman/6001691 to your computer and use it in GitHub Desktop.
The HTTP gem failing urls
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
source 'https://rubygems.org' | |
gem 'http', :path =>'/Users/oripekelman/Sites/http' | |
gem 'sinatra' |
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 'sinatra' | |
get '/200' do | |
"OK" | |
end | |
get '/301' do | |
redirect "/200", 301 | |
end | |
get '/302' do | |
redirect "/200", 302 | |
end | |
get '/303' do | |
redirect "/200", 302 | |
end | |
get '/401' do | |
halt 401, 'go away!' | |
end | |
get '/402' do | |
halt 402, 'go away!' | |
end | |
get '/403' do | |
halt 403, 'go away!' | |
end | |
get '/404' do | |
halt 404, 'go away!' | |
end | |
get '/501' do | |
halt 501, 'Boom!' | |
end | |
get '/502' do | |
halt 502, 'Boom!' | |
end | |
get '/503' do | |
halt 503, 'Boom!' | |
end |
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 'http' | |
require 'pry' | |
codes = [200] + (300..303).to_a + (400..404).to_a + (500..503).to_a | |
failing_urls = [ | |
'http://github.com', | |
'https://github.com', | |
'http://vimeo.com', | |
'http://tonyarcieri.com'] | |
sinatra_urls = codes.map {|c|"http://localhost:4567/#{c}"} | |
urls = [ | |
'http://tonyarcieri.com/', | |
'http://gmail.com', | |
'http://www.unlimitednovelty.com', | |
'http://github.com/', | |
'https://github.com/', | |
'http://vimeo.com/', | |
'http://fr.wikipedia.org/wiki/Bascule_(circuit_logique)', | |
'http://www.google.com', | |
"https://btc-e.com/api/2/btc_usd/depth"] + sinatra_urls + failing_urls | |
urls.each do |url| | |
begin | |
response = Http.get(url).response | |
puts "Worked: #{response.status_code} #{url}" | |
rescue Exception => e | |
puts "Failed: #{url}" | |
puts e.message | |
puts e.backtrace.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment