Class: Rubroxy::Proxy
- Inherits:
-
Object
- Object
- Rubroxy::Proxy
- Defined in:
- lib/rubroxy/proxy_core.rb
Overview
Main class of the proxy object, includes control methods
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#add_rules(handler) ⇒ Object
Adds a Proc object to the Proxy server.
-
#initialize(host, port, logger_level = 3) ⇒ Proxy
constructor
Creates the proxy object, defines logging levels and host:port.
-
#start_server ⇒ Object
Starts the server process, including traps for process termination.
-
#stop_server ⇒ Object
Shuts down the proxy server.
Constructor Details
#initialize(host, port, logger_level = 3) ⇒ Proxy
Creates the proxy object, defines logging levels and host:port
12 13 14 15 16 17 18 19 20 |
# File 'lib/rubroxy/proxy_core.rb', line 12 def initialize(host, port, logger_level = 3) logger = Logger.new($stderr) logger.level = logger_level access_log = [] if logger.level == 3 @server = WEBrick::HTTPProxyServer.new(Port: port, Logger: logger, AccessLog: access_log, BindAddress: host) end |
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
4 5 6 |
# File 'lib/rubroxy/proxy_core.rb', line 4 def server @server end |
Instance Method Details
#add_rules(handler) ⇒ Object
Adds a Proc object to the Proxy server
25 26 27 |
# File 'lib/rubroxy/proxy_core.rb', line 25 def add_rules(handler) @server.config[:ProxyContentHandler] = handler end |
#start_server ⇒ Object
Starts the server process, including traps for process termination
30 31 32 33 34 35 |
# File 'lib/rubroxy/proxy_core.rb', line 30 def start_server Signal.trap('INT') { stop_server } Signal.trap('TERM') { stop_server } @server.start end |
#stop_server ⇒ Object
Shuts down the proxy server
38 39 40 |
# File 'lib/rubroxy/proxy_core.rb', line 38 def stop_server @server.shutdown end |