class Ritm::Proxy::Launcher

Launches the Proxy server and the SSL Reverse Proxy with the given settings

Public Class Methods

new(session) click to toggle source
# File lib/ritm/proxy/launcher.rb, line 11
def initialize(session)
  build_settings(session)
  build_reverse_proxy
  build_proxy
end

Public Instance Methods

shutdown() click to toggle source
# File lib/ritm/proxy/launcher.rb, line 22
def shutdown
  @https.shutdown
  @http.shutdown
end
start() click to toggle source
# File lib/ritm/proxy/launcher.rb, line 17
def start
  @https.start_async
  @http.start_async
end

Private Instance Methods

build_proxy() click to toggle source
# File lib/ritm/proxy/launcher.rb, line 44
def build_proxy
  @http = Ritm::Proxy::ProxyServer.new(BindAddress: @conf.proxy.bind_address,
                                       Port: @conf.proxy.bind_port,
                                       AccessLog: [],
                                       Logger: WEBrick::Log.new(File.open(File::NULL, 'w')),
                                       https_forward: @https_forward,
                                       ProxyVia: nil,
                                       forwarder: @forwarder,
                                       ritm_conf: @conf)
end
build_reverse_proxy() click to toggle source
# File lib/ritm/proxy/launcher.rb, line 55
def build_reverse_proxy
  @https = Ritm::Proxy::SSLReverseProxy.new(@conf.ssl_reverse_proxy.bind_port,
                                            @certificate,
                                            @forwarder)
end
build_settings(session) click to toggle source
# File lib/ritm/proxy/launcher.rb, line 29
def build_settings(session)
  @conf = session.conf
  ssl_proxy_host = @conf.ssl_reverse_proxy.bind_address
  ssl_proxy_port = @conf.ssl_reverse_proxy.bind_port
  @https_forward = "#{ssl_proxy_host}:#{ssl_proxy_port}"

  request_interceptor = default_request_handler(session)
  response_interceptor = default_response_handler(session)
  @forwarder = HTTPForwarder.new(request_interceptor, response_interceptor, @conf)

  crt_path = @conf.ssl_reverse_proxy.ca.pem
  key_path = @conf.ssl_reverse_proxy.ca.key
  @certificate = ca_certificate(crt_path, key_path)
end
ca_certificate(pem, key) click to toggle source
# File lib/ritm/proxy/launcher.rb, line 61
def ca_certificate(pem, key)
  if pem.nil? || key.nil?
    Ritm::CA.create
  else
    Ritm::CA.load(File.read(pem), File.read(key))
  end
end