diff options
author | Gregor Melhorn <gregor.melhorn@gmail.com> | 2016-02-22 13:14:33 +0100 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-01-11 11:58:16 +1300 |
commit | 5c1c5a134b462b14c1a05eecb2ef7041ca5c37fa (patch) | |
tree | c43b2aec38c92e6bbaf167341d648dce2f02e661 | |
parent | b058947745d3a1bf32e5f08b96409c2aaabc2636 (diff) | |
download | rack-5c1c5a134b462b14c1a05eecb2ef7041ca5c37fa.tar.gz |
fix SSLEnable for Webrick, see https://github.com/rack/rack/issues/1013
-rw-r--r-- | lib/rack/handler/webrick.rb | 4 | ||||
-rw-r--r-- | test/spec_server.rb | 39 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb index 4affdbde..eb36d59a 100644 --- a/lib/rack/handler/webrick.rb +++ b/lib/rack/handler/webrick.rb @@ -30,6 +30,10 @@ module Rack options[:BindAddress] = options.delete(:Host) || default_host options[:Port] ||= 8080 + if options[:SSLEnable] + require 'webrick/https' + end + @server = ::WEBrick::HTTPServer.new(options) @server.mount "/", Rack::Handler::WEBrick, app yield @server if block_given? diff --git a/test/spec_server.rb b/test/spec_server.rb index 8aecc554..7b009c27 100644 --- a/test/spec_server.rb +++ b/test/spec_server.rb @@ -6,6 +6,8 @@ require 'rack/server' require 'tempfile' require 'socket' require 'open-uri' +require 'net/http' +require 'net/https' module Minitest::Spec::DSL alias :should :it @@ -144,6 +146,43 @@ describe Rack::Server do open(pidfile.path) { |f| f.read.must_equal $$.to_s } end + it "run an ssl server" do + pidfile = Tempfile.open('pidfile') { |f| break f } + FileUtils.rm pidfile.path + server = Rack::Server.new( + :app => app, + :environment => 'none', + :pid => pidfile.path, + :Port => TCPServer.open('127.0.0.1', 0){|s| s.addr[1] }, + :Host => '127.0.0.1', + :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), + :AccessLog => [], + :daemonize => false, + :server => 'webrick', + :SSLEnable => true, + :SSLCertName => [['CN', 'nobody'], ['DC', 'example']] + ) + t = Thread.new { server.start { |s| Thread.current[:server] = s } } + t.join(0.01) until t[:server] && t[:server].status != :Stop + + uri = URI.parse("https://127.0.0.1:#{server.options[:Port]}/") + + Net::HTTP.start("127.0.0.1", uri.port, + :use_ssl => true, + :verify_mode => OpenSSL::SSL::VERIFY_NONE, + :ssl_version => :SSLv3) do |http| + + request = Net::HTTP::Get.new uri + + body = http.request(request).body + body.must_equal 'success' + end + + Process.kill(:INT, $$) + t.join + open(pidfile.path) { |f| f.read.must_equal $$.to_s } + end + it "check pid file presence and running process" do pidfile = Tempfile.open('pidfile') { |f| f.write($$); break f }.path server = Rack::Server.new(pid: pidfile) |