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
glebtv-httpclient-3.2.6 test/sslsvr.rb
glebtv-httpclient-3.2.4 test/sslsvr.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/httpclient-2.3.4.1/test/sslsvr.rb
scout-5.9.2 vendor/httpclient/test/sslsvr.rb
scout-5.9.1 vendor/httpclient/test/sslsvr.rb
scout-5.9.1.pre vendor/httpclient/test/sslsvr.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/httpclient-2.3.4.1/test/sslsvr.rb
scout-5.9.0 vendor/httpclient/test/sslsvr.rb
scout-5.9.0.pre vendor/httpclient/test/sslsvr.rb
scout-5.8.9 vendor/httpclient/test/sslsvr.rb
scout-5.8.8 vendor/httpclient/test/sslsvr.rb
scout-5.8.7 vendor/httpclient/test/sslsvr.rb
scout-5.8.7.pre vendor/httpclient/test/sslsvr.rb
scout-5.8.6 vendor/httpclient/test/sslsvr.rb
glebtv-httpclient-3.2.3 test/sslsvr.rb
glebtv-httpclient-3.2.2 test/sslsvr.rb
glebtv-httpclient-3.2.1 test/sslsvr.rb
glebtv-httpclient-3.2.0 test/sslsvr.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/httpclient-2.3.4.1/test/sslsvr.rb
scout-5.8.5 vendor/httpclient/test/sslsvr.rb