Class: GQTP::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gqtp/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @options = options.dup
  @listen_host = @options[:listen_host] || @options[:listen_address]
  @listen_host ||= "0.0.0.0"
  @listen_port = @options[:listen_port] || 10043
  @upstream_host = @options[:upstream_host] || @options[:upstream_address]
  @upstream_host ||= "127.0.0.1"
  @upstream_port = @options[:upstream_port] || 10043
  # :connection is just for backward compatibility.
  @backend = @options[:backend] || @options[:connection] || :thread
  @server = Server.new(:host => @listen_host,
                       :port => @listen_port,
                       :backend => @backend)
end

Instance Attribute Details

#listen_hostObject

Returns the value of attribute listen_host.



23
24
25
# File 'lib/gqtp/proxy.rb', line 23

def listen_host
  @listen_host
end

#listen_portObject

Returns the value of attribute listen_port.



23
24
25
# File 'lib/gqtp/proxy.rb', line 23

def listen_port
  @listen_port
end

#upstream_hostObject

Returns the value of attribute upstream_host.



24
25
26
# File 'lib/gqtp/proxy.rb', line 24

def upstream_host
  @upstream_host
end

#upstream_portObject

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

#runObject



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

#shutdownObject



58
59
60
# File 'lib/gqtp/proxy.rb', line 58

def shutdown
  @server.shutdown
end