Created
September 14, 2011 04:59
-
-
Save bradgessler/1215884 to your computer and use it in GitHub Desktop.
Async Thin web server app for testing timeouts
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 'thin' | |
# curl "http://localhost:10001/?wait=5&status=500" | |
# --- | |
# wait - How many seconds should I wait before returning the status? | |
# status - HTTP return code | |
Thin::Server.start('127.0.0.1', 10001, Proc.new{|env| | |
req = Rack::Request.new(env) | |
puts "#{Time.now} - GET /?#{req.query_string}" | |
EventMachine::Timer.new(req.params['wait'].to_i) { | |
response = [(req.params['status'] || 200).to_i, {}, ''] | |
env['async.callback'].call response | |
} | |
# Tell thin to chill, we're gonna run this stack async-style | |
[-1, {}, []] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this little app to test slow upstreams in a proxy server I had to implement.