Skip to content

Instantly share code, notes, and snippets.

@bradgessler
Created September 14, 2011 04:59
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 bradgessler/1215884 to your computer and use it in GitHub Desktop.
Save bradgessler/1215884 to your computer and use it in GitHub Desktop.
Async Thin web server app for testing timeouts
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, {}, []]
})
@bradgessler
Copy link
Author

I used this little app to test slow upstreams in a proxy server I had to implement.

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