Class: Kage::ProxyServer

Inherits:
Proxy
  • Object
show all
Defined in:
lib/kage/proxy_server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProxyServer

Returns a new instance of ProxyServer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kage/proxy_server.rb', line 8

def initialize(options = {})
  @host = '0.0.0.0'
  @port = 80
  @debug = false
  @client_timeout = 15
  @backend_timeout = 30
  @backends = {}
  @master = nil
  @callbacks = {}

  options.each do |k, v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#backend_timeoutObject

Returns the value of attribute backend_timeout.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def backend_timeout
  @backend_timeout
end

#backendsObject

Returns the value of attribute backends.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def backends
  @backends
end

#callbacksObject

Returns the value of attribute callbacks.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def callbacks
  @callbacks
end

#client_timeoutObject

Returns the value of attribute client_timeout.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def client_timeout
  @client_timeout
end

#debugObject

Returns the value of attribute debug.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def debug
  @debug
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def host
  @host
end

#masterObject

Returns the value of attribute master.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def master
  @master
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/kage/proxy_server.rb', line 6

def port
  @port
end

Class Method Details

.start(options = {}, &blk) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kage/proxy_server.rb', line 36

def self.start(options = {}, &blk)
  server = new(options)
  server.instance_eval &blk

  if server.master.nil?
    raise "Configuration error: no master backend defined"
  end

  super(:host => server.host, :port => server.port, :debug => server.debug) do |conn|
    conn.extend Connection
    conn.handle(server)
  end
end

Instance Method Details

#add_backend(name, host, port = 80) ⇒ Object



32
33
34
# File 'lib/kage/proxy_server.rb', line 32

def add_backend(name, host, port = 80)
  @backends[name] = {:host => host, :port => port}
end

#add_master_backend(name, host, port = 80) ⇒ Object



27
28
29
30
# File 'lib/kage/proxy_server.rb', line 27

def add_master_backend(name, host, port = 80)
  @master = name
  add_backend(name, host, port)
end

#on_backends_finished(&blk) ⇒ Object



25
# File 'lib/kage/proxy_server.rb', line 25

def on_backends_finished(&blk); @callbacks[:on_backends_finished] = blk; end

#on_munge_headers(&blk) ⇒ Object



24
# File 'lib/kage/proxy_server.rb', line 24

def on_munge_headers(&blk); @callbacks[:on_munge_headers] = blk; end

#on_select_backends(&blk) ⇒ Object



23
# File 'lib/kage/proxy_server.rb', line 23

def on_select_backends(&blk); @callbacks[:on_select_backends] = blk; end