class MiniProxy::ProxyServer

MiniProxy server, which boots a WEBrick proxy server

Attributes

requests[RW]

Public Class Methods

new(config = {}, default = WEBrick::Config::HTTP) click to toggle source
Calls superclass method
# 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

Public Instance Methods

do_DELETE(req, res) click to toggle source
# File lib/miniproxy/proxy_server.rb, line 25
def do_DELETE(req, res)
  perform_proxy_request(req, res) do |http, path, header|
    http.delete(path, header)
  end
end
do_PATCH(req, res) click to toggle source
# File lib/miniproxy/proxy_server.rb, line 31
def do_PATCH(req, res)
  perform_proxy_request(req, res) do |http, path, header|
    http.patch(path, req.body || "", header)
  end
end
do_POST(req, res) click to toggle source
# File lib/miniproxy/proxy_server.rb, line 37
def do_POST(req, res)
  perform_proxy_request(req, res, Net::HTTP::Post, StringIO.new(req.body))
end
do_PUT(req, res) click to toggle source
# File lib/miniproxy/proxy_server.rb, line 19
def do_PUT(req, res)
  perform_proxy_request(req, res) do |http, path, header|
    http.put(path, req.body || "", header)
  end
end
service(req, res) click to toggle source
Calls superclass method
# File lib/miniproxy/proxy_server.rb, line 54
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