class QuickAndRuby::Proxy::Proxy

service proxy instance

Attributes

options[R]
proxy_service[R]

Public Class Methods

new(options, proxy_service = WEBrick::HTTPProxyServer) click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 11
def initialize(options, proxy_service = WEBrick::HTTPProxyServer)
  @options = options
  @proxy_service = proxy_service
end

Public Instance Methods

start() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 16
def start
  configure_trap
  proxy.start
end

Private Instance Methods

base_proxy_options() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 42
def base_proxy_options
  { BindAddress: options[:bind],
    Port: options[:port] }
end
configure_trap() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 63
def configure_trap
  trap('INT') { proxy.shutdown }
  trap('TERM') { proxy.shutdown }
end
logger() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 25
def logger
  unless @logger
    @logger = Logger.new($stderr)
    @logger.level = Logger::DEBUG
  end
  @logger
end
logger_options() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 59
def logger_options
  { Logger: logger }
end
proxy() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 33
def proxy
  @proxy ||= proxy_service.new(**proxy_options)
end
proxy_options() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 37
def proxy_options
  base_proxy_options.merge(remote_proxy_options)
                    .merge(logger_options)
end
remote_proxy_options() click to toggle source
# File lib/quick_and_ruby/proxy/proxy.rb, line 47
def remote_proxy_options
  if options[:proxy_host]
    uri = OpenStruct.new(
      userinfo: options[:user],
      host: options[:proxy_host],
      port: options[:proxy_port]
    )
    return { ProxyURI: uri }
  end
  {}
end