Skip to content

Instantly share code, notes, and snippets.

@ktheory
Created July 25, 2011 00:52
Show Gist options
  • Save ktheory/1103322 to your computer and use it in GitHub Desktop.
Save ktheory/1103322 to your computer and use it in GitHub Desktop.
em-proxy test with Rack
#!/usr/bin/env ruby
require 'em-proxy'
Proxy.start(:host => "0.0.0.0", :port => 3000) do |conn|
conn.server :fast, :host => '127.0.0.1', :port => 3001
conn.server :slow, :host => '127.0.0.1', :port => 3002
conn.on_data do |data|
data
end
conn.on_response do |server, resp|
if server == :fast
resp
else
puts "Got slow resp"
end
end
end
# Rack app with configurable speed:
#
# In one shell, run the fast app:
# $ thin -R sleepy.ru -p 3001 start
#
# In another shell, run the slow app:
# $ SLEEP=1 thin -R sleepy.ru -p 3002 start
require 'rack'
SLEEP = ENV['SLEEP'].to_i
sleepy = lambda do |env|
sleep SLEEP
[200, {}, "Slept for #{SLEEP}\n"]
end
run sleepy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment