Skip to content

Instantly share code, notes, and snippets.

@mje113
Created March 28, 2014 10:43
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 mje113/9829932 to your computer and use it in GitHub Desktop.
Save mje113/9829932 to your computer and use it in GitHub Desktop.
manticore redirect test
require 'manticore'
require 'webrick'
class Redirector < WEBrick::HTTPServlet::AbstractServlet
PORT = 9123
def do_GET(request, response)
case request.path
when '/'
response.status = 200
response.body = 'Success!'
when '/redirect_302'
response.status = 302
response['Location'] = "http://localhost:#{PORT}/"
when '/redirect_307'
response.status = 307
response['Location'] = "http://localhost:#{PORT}/"
end
end
def do_POST(request, response)
case request.path
when '/'
response.status = 200
response.body = 'Success!'
when '/redirect_302'
response.status = 302
response['Location'] = "http://localhost:#{PORT}/"
when '/redirect_307'
response.status = 307
response['Location'] = "http://localhost:#{PORT}/"
end
end
end
Server = WEBrick::HTTPServer.new(:Port => Redirector::PORT, :AccessLog => [])
Server.mount '/', Redirector
t = Thread.new { Server.start }
trap('INT') do
Server.shutdown
exit
end
client = Manticore::Client.new(
request_timeout: 60,
connect_timeout: 25,
socket_timeout: 25,
pool_max: 10,
pool_max_per_route: 2,
follow_redirects: true
)
puts "GET 302: #{client.get('http://localhost:9123/redirect_302').body}"
puts "GET 307: #{client.get('http://localhost:9123/redirect_307').body}"
puts "POST 302: #{client.post('http://localhost:9123/redirect_302').body}"
puts "POST 307: #{client.post('http://localhost:9123/redirect_307').body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment