Created
July 25, 2011 00:52
-
-
Save ktheory/1103322 to your computer and use it in GitHub Desktop.
em-proxy test with Rack
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
# 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