examples/http_proxy.rb in em-proxy-0.1.8 vs examples/http_proxy.rb in em-proxy-0.1.9
- old
+ new
@@ -10,29 +10,35 @@
port = 9889
puts "listening on #{host}:#{port}..."
Proxy.start(:host => host, :port => port) do |conn|
+ @buffer = ''
+
@p = Http::Parser.new
@p.on_headers_complete = proc do |h|
session = UUID.generate
puts "New session: #{session} (#{h.inspect})"
host, port = h['Host'].split(':')
conn.server session, :host => host, :port => (port || 80) #, :bind_host => conn.sock[0] - # for bind ip
-
- conn.relay_to_servers @buffer
- @buffer.clear
+ conn.relay_to_servers @buffer
+ @buffer = nil
end
- @buffer = ''
-
conn.on_connect do |data,b|
puts [:on_connect, data, b].inspect
end
conn.on_data do |data|
+ if @buffer
+ @buffer << data
+
+ nil
+ else
+ @
+
@buffer << data
@p << data
data
end