Class: GQTP::Proxy
- Inherits:
-
Object
- Object
- GQTP::Proxy
- Defined in:
- lib/gqtp/proxy.rb
Instance Attribute Summary collapse
-
#listen_host ⇒ Object
Returns the value of attribute listen_host.
-
#listen_port ⇒ Object
Returns the value of attribute listen_port.
-
#upstream_host ⇒ Object
Returns the value of attribute upstream_host.
-
#upstream_port ⇒ Object
Returns the value of attribute upstream_port.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #run ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Proxy
Returns a new instance of Proxy.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gqtp/proxy.rb', line 25 def initialize(={}) = .dup @listen_host = [:listen_host] || [:listen_address] @listen_host ||= "0.0.0.0" @listen_port = [:listen_port] || 10043 @upstream_host = [:upstream_host] || [:upstream_address] @upstream_host ||= "127.0.0.1" @upstream_port = [:upstream_port] || 10043 # :connection is just for backward compatibility. @backend = [:backend] || [:connection] || :thread @server = Server.new(:host => @listen_host, :port => @listen_port, :backend => @backend) end |
Instance Attribute Details
#listen_host ⇒ Object
Returns the value of attribute listen_host.
23 24 25 |
# File 'lib/gqtp/proxy.rb', line 23 def listen_host @listen_host end |
#listen_port ⇒ Object
Returns the value of attribute listen_port.
23 24 25 |
# File 'lib/gqtp/proxy.rb', line 23 def listen_port @listen_port end |
#upstream_host ⇒ Object
Returns the value of attribute upstream_host.
24 25 26 |
# File 'lib/gqtp/proxy.rb', line 24 def upstream_host @upstream_host end |
#upstream_port ⇒ Object
Returns the value of attribute upstream_port.
24 25 26 |
# File 'lib/gqtp/proxy.rb', line 24 def upstream_port @upstream_port end |
Instance Method Details
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gqtp/proxy.rb', line 40 def run @server.on_connect do |client| create_backend end @server.on_request do |request, client, backend| backend.write(request.header.pack, request.body) do backend.read(Header.size) do |header| response_header = Header.parse(header) backend.read(response_header.size) do |body| client.write(header, body) do end end end end end @server.run end |
#shutdown ⇒ Object
58 59 60 |
# File 'lib/gqtp/proxy.rb', line 58 def shutdown @server.shutdown end |