Class: EvilProxy::HTTPProxyServer
- Inherits:
-
WEBrick::HTTPProxyServer
- Object
- WEBrick::HTTPProxyServer
- EvilProxy::HTTPProxyServer
show all
- Defined in:
- lib/evil-proxy/httpproxy.rb
Constant Summary
collapse
- DEFAULT_CALLBACKS =
Hash.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}, default = WEBrick::Config::HTTP) ⇒ HTTPProxyServer
Returns a new instance of HTTPProxyServer.
9
10
11
12
13
14
15
16
17
|
# File 'lib/evil-proxy/httpproxy.rb', line 9
def initialize config = {}, default = WEBrick::Config::HTTP
initialize_callbacks config
fire :when_initialize, config, default
config.merge!(
Logger: WEBrick::Log.new(nil, 0),
AccessLog: []
) if config[:Quiet]
super
end
|
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
5
6
7
|
# File 'lib/evil-proxy/httpproxy.rb', line 5
def callbacks
@callbacks
end
|
Class Method Details
.define_callback_methods(callback) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/evil-proxy/httpproxy.rb', line 57
def self.define_callback_methods callback
define_method callback do |&block|
@callbacks[callback] ||= []
@callbacks[callback] << block
end
define_singleton_method callback do |&block|
DEFAULT_CALLBACKS[callback] ||= []
DEFAULT_CALLBACKS[callback] << block
end
end
|
Instance Method Details
#exit ⇒ Object
33
34
35
36
|
# File 'lib/evil-proxy/httpproxy.rb', line 33
def exit
self.logger.info "#{self.class}#exit: pid=#{$$}"
Kernel.exit
end
|
#fire(key, *args) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/evil-proxy/httpproxy.rb', line 44
def fire key, *args
return unless @callbacks[key]
@callbacks[key].each do |callback|
instance_exec *args, &callback
end
end
|
#restart(&block) ⇒ Object
38
39
40
41
42
|
# File 'lib/evil-proxy/httpproxy.rb', line 38
def restart &block
self.logger.info "#{self.class}#restart: pid=#{$$}" if @status == :Running
initialize_callbacks Hash.new
instance_exec &block if block
end
|
#service(req, res) ⇒ Object
51
52
53
54
55
|
# File 'lib/evil-proxy/httpproxy.rb', line 51
def service req, res
fire :before_request, req
super
fire :before_response, req, res
end
|
#start ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/evil-proxy/httpproxy.rb', line 19
def start
begin
fire :when_start
super
ensure
fire :when_shutdown
end
end
|
#stop ⇒ Object
28
29
30
31
|
# File 'lib/evil-proxy/httpproxy.rb', line 28
def stop
self.logger.info "#{self.class}#stop: pid=#{$$}"
super
end
|