lib/slinky/proxy_server.rb in slinky-0.6.1 vs lib/slinky/proxy_server.rb in slinky-0.7.0
- old
+ new
@@ -42,13 +42,10 @@
Proxy.start(:host => "0.0.0.0", :port => port){|conn|
proxy = nil
start_time = nil
conn.server :slinky, :host => "127.0.0.1", :port => slinky_port
- proxy_servers.each{|p|
- conn.server p, :host => p[0], :port => p[1]
- }
conn.on_data do |data|
begin
_, path = data.match(ProxyServer::HTTP_MATCHER)[1..2]
proxy = ProxyServer.find_matcher(proxies, path)
@@ -56,10 +53,12 @@
server = if proxy
new_path = ProxyServer.rewrite_path path, proxy
data = ProxyServer.replace_path(data, path, new_path, proxy[1].path)
new_host = proxy[1].select(:host, :port).join(":")
data = ProxyServer.replace_host(data, new_host)
+ conn.server [proxy[1].host, proxy[1].port],
+ :host => proxy[1].host, :port => proxy[1].port
[proxy[1].host, proxy[1].port]
else :slinky
end
[data, [server]]
rescue
@@ -73,10 +72,10 @@
if opt && opt["lag"]
# we want to get as close as possible to opt["lag"], so we
# take into account the lag from the backend server
so_far = Time.now - start_time
time = opt["lag"]/1000.0-so_far
- EM.add_timer (time > 0 ? time : 0) do
+ EM.add_timer(time > 0 ? time : 0) do
conn.send_data resp
end
else
resp
end