Class: MiniProxy::FakeSSLServer

Inherits:
WEBrick::HTTPServer
  • Object
show all
Defined in:
lib/miniproxy/fake_ssl_server.rb

Overview

MiniProxy fake SSL enabled server, which receives relayed requests from the ProxyServer

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, default = WEBrick::Config::HTTP) ⇒ FakeSSLServer

Returns a new instance of FakeSSLServer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/miniproxy/fake_ssl_server.rb', line 8

def initialize(config = {}, default = WEBrick::Config::HTTP)
  @allowed_hosts = ["127.0.0.1", "localhost", config[:MiniProxyHost]].compact

  config = config.merge({
    Logger: WEBrick::Log.new(nil, 0), # silence logging
    AccessLog: [], # silence logging
    SSLEnable: true,
    SSLCertificate: OpenSSL::X509::Certificate.new(certificate_file("cert.pem")),
    SSLPrivateKey: OpenSSL::PKey::RSA.new(certificate_file("cert.key")),
    SSLVerifyClient: OpenSSL::SSL::VERIFY_NONE,
  })

  super(config, default)
end

Instance Method Details

#service(req, res) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/miniproxy/fake_ssl_server.rb', line 23

def service(req, res)
  if @allowed_hosts.include?(req.host)
    super(req, res)
  else
    self.config[:MockHandlerCallback].call(req, res)
  end
end