Sha256: 95a55cdca3c98e685cb8a170c0d04d78cfc75273d1e848cc94656af53bf1d9a8

Contents?: true

Size: 974 Bytes

Versions: 8

Compression:

Stored size: 974 Bytes

Contents

require 'lib/em-proxy'

Proxy.start(:host => "0.0.0.0", :port => 80, :debug => false) do |conn|
  # Specifying :relay_server or :relay_client is useful if only requests or responses 
  # need to be processed. The proxy throughput will roughly double.
  conn.server :srv, :host => "127.0.0.1", :port => 81, :relay_client => true, :relay_server => true

  conn.on_connect do
    p [:on_connect, "#{conn.peer.join(':')} connected"]
  end

  # modify / process request stream
  # on_data will not be called when :relay_server => true is passed as server option
  conn.on_data do |data|
    p [:on_data, data]
    data
  end
 
  # modify / process response stream
  # on_response will not be called when :relay_client => true is passed as server option
  conn.on_response do |backend, resp|
    p [:on_response, backend, resp]
    # resp = "HTTP/1.1 200 OK\r\nConnection: close\r\nDate: Thu, 30 Apr 2009 03:53:28 GMT\r\nContent-Type: text/plain\r\n\r\nHar!"
    resp
  end  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
em-proxy-0.1.9 examples/relay_port_forward.rb
em-proxy-0.1.8 examples/relay_port_forward.rb
em-proxy-0.1.7 examples/relay_port_forward.rb
em-proxy-0.1.6 examples/relay_port_forward.rb
em-proxy-0.1.5 examples/relay_port_forward.rb
em-proxy-0.1.4 examples/relay_port_forward.rb
em-proxy-0.1.3 examples/relay_port_forward.rb
em-proxy-0.1.2 examples/relay_port_forward.rb