Sha256: c7f30cbf051c14c17daff2e34590497c617a537c42a7d7d79b188aa5ab1b6574

Contents?: true

Size: 1.34 KB

Versions: 156

Compression:

Stored size: 1.34 KB

Contents

require 'webrick/https'
require 'logger'
require 'rbconfig'

PORT = 17171
DIR = File.dirname(File.expand_path(__FILE__))

def cert(filename)
  OpenSSL::X509::Certificate.new(File.open(File.join(DIR, filename)) { |f|
    f.read
  })
end

def key(filename)
  OpenSSL::PKey::RSA.new(File.open(File.join(DIR, filename)) { |f|
    f.read
  })
end

def do_hello(req, res)
  res['content-type'] = 'text/html'
  res.body = "hello"
end

logger = Logger.new(STDERR)
logger.level = Logger::Severity::FATAL	# avoid logging SSLError (ERROR level)

server = WEBrick::HTTPServer.new(
  :BindAddress => "localhost",
  :Logger => logger,
  :Port => PORT,
  :AccessLog => [],
  :DocumentRoot => DIR,
  :SSLEnable => true,
  :SSLCACertificateFile => File.join(DIR, 'ca.cert'),
  :SSLCertificate => cert('server.cert'),
  :SSLPrivateKey => key('server.key'),
  :SSLVerifyClient => nil, #OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT|OpenSSL::SSL::VERIFY_PEER,
  :SSLClientCA => cert('ca.cert'),
  :SSLCertName => nil
)
trap(:INT) do
  server.shutdown
end
[:hello].each do |sym|
  server.mount(
    "/#{sym}",
    WEBrick::HTTPServlet::ProcHandler.new(method("do_#{sym}").to_proc)
  )
end

t = Thread.new {
  Thread.current.abort_on_exception = true
  server.start
}
while server.status != :Running
  sleep 0.1
  unless t.alive?
    t.join
    raise
  end
end
STDOUT.sync = true
puts $$
t.join

Version data entries

156 entries across 148 versions & 14 rubygems

Version Path
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
scout-5.9.12 vendor/httpclient/test/sslsvr.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
scout-5.9.11 vendor/httpclient/test/sslsvr.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb
httpclient-2.8.3 test/sslsvr.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/sslsvr.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/sslsvr.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/sslsvr.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/httpclient-2.8.0/test/sslsvr.rb
httpclient-2.8.2.4 test/sslsvr.rb
httpclient-2.8.2.3 test/sslsvr.rb
httpclient-2.8.2.2 test/sslsvr.rb
httpclient-2.8.2.1 test/sslsvr.rb