Class: MiniProxy::ProxyServer
- Inherits:
-
WEBrick::HTTPProxyServer
- Object
- WEBrick::HTTPProxyServer
- MiniProxy::ProxyServer
- Defined in:
- lib/miniproxy/proxy_server.rb
Overview
MiniProxy server, which boots a WEBrick proxy server
Instance Attribute Summary collapse
-
#requests ⇒ Object
Returns the value of attribute requests.
Instance Method Summary collapse
- #do_DELETE(req, res) ⇒ Object
- #do_PATCH(req, res) ⇒ Object
- #do_PUT(req, res) ⇒ Object
-
#initialize(config = {}, default = WEBrick::Config::HTTP) ⇒ ProxyServer
constructor
A new instance of ProxyServer.
- #service(req, res) ⇒ Object
Constructor Details
#initialize(config = {}, default = WEBrick::Config::HTTP) ⇒ ProxyServer
Returns a new instance of ProxyServer.
9 10 11 12 13 14 15 16 |
# File 'lib/miniproxy/proxy_server.rb', line 9 def initialize(config = {}, default = WEBrick::Config::HTTP) config = config.merge({ Logger: WEBrick::Log.new(nil, 0), # silence logging AccessLog: [], # silence logging }) super(config, default) end |
Instance Attribute Details
#requests ⇒ Object
Returns the value of attribute requests.
7 8 9 |
# File 'lib/miniproxy/proxy_server.rb', line 7 def requests @requests end |
Instance Method Details
#do_DELETE(req, res) ⇒ Object
22 23 24 |
# File 'lib/miniproxy/proxy_server.rb', line 22 def do_DELETE(req, res) perform_proxy_request(req, res, Net::HTTP::Delete) end |
#do_PATCH(req, res) ⇒ Object
26 27 28 |
# File 'lib/miniproxy/proxy_server.rb', line 26 def do_PATCH(req, res) perform_proxy_request(req, res, Net::HTTP::Patch, req.body_reader) end |
#do_PUT(req, res) ⇒ Object
18 19 20 |
# File 'lib/miniproxy/proxy_server.rb', line 18 def do_PUT(req, res) perform_proxy_request(req, res, Net::HTTP::Put, req.body_reader) end |
#service(req, res) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/miniproxy/proxy_server.rb', line 30 def service(req, res) if self.config[:AllowedRequestCheck].call(req) super(req, res) else if req.request_method == "CONNECT" is_ssl = req.unparsed_uri.include?(":443") # If something is trying to initiate an SSL connection, rewrite # the URI to point to our fake server so we can stub SSL requests. if is_ssl req.instance_variable_set(:@unparsed_uri, "localhost:#{self.config[:FakeServerPort]}") end super(req, res) else # Otherwise, call our handler to respond with an appropriate # mock for the request. self.config[:MockHandlerCallback].call(req, res) end end end |