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
httpclient-2.5.3.1 test/sslsvr.rb
httpclient-2.5.3 test/sslsvr.rb
httpclient-2.5.2 test/sslsvr.rb
httpclient-2.5.1 test/sslsvr.rb
scout-5.9.7.2.pre vendor/httpclient/test/sslsvr.rb
httpclient-2.5.0 test/sslsvr.rb
scout-5.9.8.pre vendor/httpclient/test/sslsvr.rb
scout-5.9.7.1 vendor/httpclient/test/sslsvr.rb
bterlson-httpclient-2.1.4 test/sslsvr.rb
bterlson-httpclient-2.1.5 test/sslsvr.rb
glebtv-httpclient-3.2.8 test/sslsvr.rb
scout-5.9.7.pre vendor/httpclient/test/sslsvr.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/httpclient-2.4.0/test/sslsvr.rb
scout-5.9.5 vendor/httpclient/test/sslsvr.rb
scout-5.9.4 vendor/httpclient/test/sslsvr.rb
scout-5.9.4.pre vendor/httpclient/test/sslsvr.rb
httpclient-2.4.0 test/sslsvr.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/httpclient-2.3.4.1/test/sslsvr.rb
scout-5.9.3 vendor/httpclient/test/sslsvr.rb
glebtv-httpclient-3.2.7 test/sslsvr.rb