Class: ExperellaProxy::Server

Inherits:
Object
  • Object
show all
Includes:
Globals
Defined in:
lib/experella-proxy/server.rb

Overview

The server starts the Proxy and provides callbacks/block hooks for client Connections

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Globals

#config, #connection_manager, #event, #logger

Constructor Details

#initialize(options) ⇒ Server

Constructor

Parameters:

  • options (Hash)

    options Hash passed to the proxy



9
10
11
# File 'lib/experella-proxy/server.rb', line 9

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/experella-proxy/server.rb', line 13

def options
  @options
end

Instance Method Details

#runObject

Runs the proxy server with given options

Opens a block passed to every Connection

You can add logic to

Connection#connected in on_connect Connection#receive_data in on_data, must return data Connection#relay_from_backend in on_response, must return resp Connection#unbind_backend in on_finish Connection#unbind in on_unbind



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/experella-proxy/server.rb', line 27

def run
  Proxy.start(options = {}) do |conn|
    event(:server_new_connection, :msec => msec, :signature => signature)

    # called on successful backend connection
    # backend is the name of the connected server
    conn.on_connect do |backend|

    end

    # modify / process request stream
    # and return modified data
    conn.on_data do |data|
      data
    end

    # modify / process response stream
    # and return modified response
    conn.on_response do |backend, resp|
      resp
    end

    # termination logic
    conn.on_finish do |backend|

    end

    # called if client terminates connection
    # or timeout occurs
    conn.on_unbind do

    end
  end
end