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
# File 'lib/gqtp/proxy.rb', line 25

def initialize(options={})
  @options = options.dup
  @listen_address = @options[:listen_address] || "0.0.0.0"
  @listen_port = @options[:listen_port] || 10041
  @upstream_address = @options[:upstream_address] || "127.0.0.1"
  @upstream_port = @options[:upstream_port] || 10041
  @connection = @options[:connection] || :thread
  @server = Server.new(:address => @listen_address,
                       :port => @listen_port,
                       :connection => @connection)
end

Instance Attribute Details

#listen_addressObject

Returns the value of attribute listen_address.



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

def listen_address
  @listen_address
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_addressObject

Returns the value of attribute upstream_address.



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

def upstream_address
  @upstream_address
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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gqtp/proxy.rb', line 37

def run
  @server.on_connect do |client|
    create_connection
  end
  @server.on_request do |request, client, connection|
    connection.write(request.header.pack, request.body) do
      connection.read(Header.size) do |header|
        response_header = Header.parse(header)
        connection.read(response_header.size) do |body|
          client.write(header, body) do
          end
        end
      end
    end
  end
  @server.run
end

#shutdownObject



55
56
57
# File 'lib/gqtp/proxy.rb', line 55

def shutdown
  @server.shutdown
end