Class: CapProxy::Server
- Inherits:
-
Object
- Object
- CapProxy::Server
- Defined in:
- lib/cap_proxy/server.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#proxy_host ⇒ Object
readonly
Returns the value of attribute proxy_host.
-
#proxy_port ⇒ Object
readonly
Returns the value of attribute proxy_port.
-
#target_host ⇒ Object
readonly
Returns the value of attribute target_host.
-
#target_port ⇒ Object
readonly
Returns the value of attribute target_port.
Instance Method Summary collapse
- #capture(filter_param, &handler) ⇒ Object
-
#initialize(bind_address, target, log = nil) ⇒ Server
constructor
A new instance of Server.
- #reset_filters! ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(bind_address, target, log = nil) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cap_proxy/server.rb', line 11 def initialize(bind_address, target, log = nil) proxy_host, proxy_port = bind_address.split(":", 2) target_host, target_port = target.split(":", 2) @log = log @proxy_port = proxy_port @proxy_host = proxy_host @target_host = target_host @target_port = target_port reset_filters! end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def filters @filters end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def log @log end |
#proxy_host ⇒ Object (readonly)
Returns the value of attribute proxy_host.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def proxy_host @proxy_host end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def proxy_port @proxy_port end |
#target_host ⇒ Object (readonly)
Returns the value of attribute target_host.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def target_host @target_host end |
#target_port ⇒ Object (readonly)
Returns the value of attribute target_port.
9 10 11 |
# File 'lib/cap_proxy/server.rb', line 9 def target_port @target_port end |
Instance Method Details
#capture(filter_param, &handler) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cap_proxy/server.rb', line 28 def capture(filter_param, &handler) filter = case filter_param when Hash Filter.from_hash(filter_param) when Filter filter_param else raise RuntimeError("#capture requires a hash or a Filter object") end @filters.push filter: filter, handler: handler filter end |
#reset_filters! ⇒ Object
24 25 26 |
# File 'lib/cap_proxy/server.rb', line 24 def reset_filters! @filters = ThreadSafe::Array.new end |
#run! ⇒ Object
43 44 45 46 |
# File 'lib/cap_proxy/server.rb', line 43 def run! log.info "CapProxy: Listening on #{proxy_host}:#{proxy_port}" if log EM.start_server proxy_host, proxy_port, Client, self end |