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
- SUPPORTED_METHODS =
%w(GET HEAD POST PUT PATCH DELETE OPTIONS CONNECT).freeze
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.
11
12
13
14
15
16
17
18
19
|
# File 'lib/evil-proxy/httpproxy.rb', line 11
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
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/evil-proxy/httpproxy.rb', line 59
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
#do_DELETE(req, res) ⇒ Object
77
78
79
80
81
|
# File 'lib/evil-proxy/httpproxy.rb', line 77
def do_DELETE(req, res)
perform_proxy_request(req, res) do |http, path, |
http.delete(path, )
end
end
|
#do_OPTIONS(_req, res) ⇒ Object
89
90
91
|
# File 'lib/evil-proxy/httpproxy.rb', line 89
def do_OPTIONS(_req, res)
res['allow'] = SUPPORTED_METHODS.join(',')
end
|
#do_PATCH(req, res) ⇒ Object
83
84
85
86
87
|
# File 'lib/evil-proxy/httpproxy.rb', line 83
def do_PATCH(req, res)
perform_proxy_request(req, res) do |http, path, |
http.patch(path, req.body || '', )
end
end
|
#do_PUT(req, res) ⇒ Object
71
72
73
74
75
|
# File 'lib/evil-proxy/httpproxy.rb', line 71
def do_PUT(req, res)
perform_proxy_request(req, res) do |http, path, |
http.put(path, req.body || '', )
end
end
|
#exit ⇒ Object
35
36
37
38
|
# File 'lib/evil-proxy/httpproxy.rb', line 35
def exit
self.logger.info "#{self.class}#exit: pid=#{$$}"
Kernel.exit
end
|
#fire(key, *args) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/evil-proxy/httpproxy.rb', line 46
def fire key, *args
return unless @callbacks[key]
@callbacks[key].each do |callback|
instance_exec *args, &callback
end
end
|
#restart(&block) ⇒ Object
40
41
42
43
44
|
# File 'lib/evil-proxy/httpproxy.rb', line 40
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
53
54
55
56
57
|
# File 'lib/evil-proxy/httpproxy.rb', line 53
def service req, res
fire :before_request, req
super
fire :before_response, req, res
end
|
#start ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/evil-proxy/httpproxy.rb', line 21
def start
begin
fire :when_start
super
ensure
fire :when_shutdown
end
end
|
#stop ⇒ Object
30
31
32
33
|
# File 'lib/evil-proxy/httpproxy.rb', line 30
def stop
self.logger.info "#{self.class}#stop: pid=#{$$}"
super
end
|