Skip to content

Commit

Permalink
Remove WEBrick
Browse files Browse the repository at this point in the history
WEBrick is not recommended for production usage, and the rackup gem
dropped the dependency on it. [1], [2]

With these changes in mind, just recommend Puma as the web server, for
simplicity.

[1]: ruby/webrick@70b026c
[2]: rack/rackup#23
  • Loading branch information
dentarg committed Nov 7, 2024
1 parent 955682e commit 4a55850
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 34 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ end
Install the gems needed:

```shell
gem install sinatra
gem install rackup
gem install puma # or any other server (optional step)
gem install sinatra rackup puma
```

And run with:
Expand Down Expand Up @@ -2087,12 +2085,8 @@ set :protection, :session => true

<dt>server_settings</dt>
<dd>
If you are using a WEBrick web server, presumably for your development
environment, you can pass a hash of options to <tt>server_settings</tt>,
such as <tt>SSLEnable</tt> or <tt>SSLVerifyClient</tt>. However, web
servers such as Puma do not support this, so you can set
<tt>server_settings</tt> by defining it as a method when you call
<tt>configure</tt>.
You can pass a hash of options to <tt>server_settings</tt>,
such as <tt>Host</tt> or <tt>Port</tt>.
</dd>

<dt>sessions</dt>
Expand Down Expand Up @@ -2813,7 +2807,7 @@ _Paraphrasing from
by Konstantin_

Sinatra doesn't impose any concurrency model but leaves that to the
underlying Rack handler (server) like Puma or WEBrick. Sinatra
underlying Rack handler (server) like Puma or Falcon. Sinatra
itself is thread-safe, so there won't be any problem if the Rack handler
uses a threaded model of concurrency.

Expand Down
14 changes: 7 additions & 7 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1600,20 +1600,20 @@ def quit!
alias stop! quit!

# Run the Sinatra app as a self-hosted server using
# Puma, Falcon, or WEBrick (in that order). If given a block, will call
# Puma, Falcon (in that order). If given a block, will call
# with the constructed handler once we have taken the stage.
def run!(options = {}, &block)
unless defined?(Rackup::Handler)
rackup_warning = <<~MISSING_RACKUP
Sinatra could not start, the "rackup" gem was not found!
Sinatra could not start, the required gems weren't found!
Add it to your bundle with:
Add them to your bundle with:
bundle add rackup
bundle add rackup puma
or install it with:
or install them with:
gem install rackup
gem install rackup puma
MISSING_RACKUP
warn rackup_warning
Expand Down Expand Up @@ -1963,7 +1963,7 @@ class << self
set :running_server, nil
set :handler_name, nil
set :traps, true
set :server, %w[HTTP webrick]
set :server, %w[]
set :bind, proc { development? ? 'localhost' : '0.0.0.0' }
set :port, Integer(ENV['PORT'] && !ENV['PORT'].empty? ? ENV['PORT'] : 4567)
set :quiet, false
Expand Down
8 changes: 4 additions & 4 deletions rack-protection/lib/rack/protection/authenticity_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ module Protection
# Install the gem, then run the program:
#
# gem install 'rack-protection'
# ruby server.rb
# puma server.ru
#
# Here is <tt>server.rb</tt>:
# Here is <tt>server.ru</tt>:
#
# require 'rack/protection'
# require 'rack/session'
#
# app = Rack::Builder.app do
# use Rack::Session::Cookie, secret: 'secret'
# use Rack::Session::Cookie, secret: 'CHANGEMEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
# use Rack::Protection::AuthenticityToken
#
# run -> (env) do
Expand Down Expand Up @@ -88,7 +88,7 @@ module Protection
# end
# end
#
# Rack::Handler::WEBrick.run app
# run app
#
# == Example: Customize which POST parameter holds the token
#
Expand Down
4 changes: 0 additions & 4 deletions test/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ def command
end
end

def webrick?
name.to_s == "webrick"
end

def puma?
name.to_s == "puma"
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration_start_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_app_start_without_rackup
env = { "BUNDLE_GEMFILE" => gem_file }

with_process(command: command, env: env) do |process, read_io|
assert wait_for_output(read_io, /Sinatra could not start, the "rackup" gem was not found/)
assert wait_for_output(read_io, /Sinatra could not start, the required gems weren't found/)
end
end

Expand Down
4 changes: 1 addition & 3 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ class IntegrationTest < Minitest::Test
count = server.log.scan("GET /ping?x=#{random}").count
if server.net_http_server?
assert_equal 0, count
elsif server.webrick?
assert(count > 0)
else
assert_equal(1, count)
end
end

it 'streams' do
next if server.webrick? or server.trinidad?
next if server.trinidad?
times, chunks = [Process.clock_gettime(Process::CLOCK_MONOTONIC)], []
server.get_stream do |chunk|
next if chunk.empty?
Expand Down
5 changes: 0 additions & 5 deletions test/settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,6 @@ def pub; end
end

describe 'server' do
it 'includes webrick' do
assert @base.server.include?('webrick')
assert @application.server.include?('webrick')
end

it 'includes puma' do
assert @base.server.include?('puma')
assert @application.server.include?('puma')
Expand Down

0 comments on commit 4a55850

Please sign in to comment.