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
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/httpclient-2.8.3/test/sslsvr.rb
httpclient-fixcerts-2.8.5 test/sslsvr.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.9 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.6 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.4 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.3 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.2 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.1 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
video_chat_get-0.1.0 vendor/bundle/ruby/2.5.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/httpclient-2.8.3/test/sslsvr.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/httpclient-2.8.3/test/sslsvr.rb