Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rack 3 support #1857

Merged
merged 29 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eff32e1
Don't allow Rack 3 builds to fail
dentarg Dec 23, 2022
482b157
Add `rackup`, `rack-session` as dependencies
dentarg Dec 24, 2022
c5f9817
Remove Rack 2 jobs
dentarg Dec 24, 2022
a86a32b
Run tests for sinatra-contrib and rack-protection
dentarg Dec 24, 2022
5efc85e
Rack 3 requires all response headers to be lowercase
dentarg Dec 28, 2022
c83b7f2
`SERVER_PROTOCOL` -> `HTTP_VERSION`
dentarg Dec 28, 2022
0b4622f
Rack 3 does not allow newlines in headers
dentarg Dec 28, 2022
943cfaa
Find `RACK_SESSION_UNPACKED_COOKIE_DATA`
dentarg Dec 28, 2022
26aeec7
rack-protection tests now pass (on Ruby 2.7.7)
dentarg Dec 28, 2022
1396f08
Cookie attributes are lowercase in Rack 3
dentarg Dec 28, 2022
0a9b043
sinatra-contrib tests now pass
dentarg Dec 29, 2022
44377b2
Fix server registration
dentarg Dec 30, 2022
8e6d11c
Update routing test `handles params without a value`
dentarg Feb 9, 2023
217c5db
Restore `continue-on-error`
dentarg Feb 13, 2023
a4a786a
Depend on `rackup` and `rack-session` >=2.0.0
dentarg Feb 24, 2023
8da32a4
`Rack::File` -> `Rack::Files` again
dentarg Feb 24, 2023
c129d58
Support `text/javascript` as JavaScript MIME type
dentarg Feb 25, 2023
41d6063
`Rack::Handler` -> `Rackup::Handler`
dentarg Mar 4, 2023
5b28218
Revert "Update routing test `handles params without a value`"
dentarg May 15, 2023
d3dfc19
Update rack requirement in rack-protection gemspec
dentarg Aug 7, 2023
4ba8664
Puma 5 is not compatible with Rack 3
dentarg Aug 7, 2023
7a514e2
Test with rack head
dentarg Aug 7, 2023
a378414
Fix typo in spec description
dentarg Nov 26, 2023
e721af6
Require rack 3.0.0, not 3.0.0.beta1
dentarg Dec 23, 2023
7a16094
rack-protection depends on rack-session
dentarg Dec 23, 2023
1e37204
CI: use rack stable (Rack >= 3.0)
dentarg Jan 2, 2024
8a78d8b
Make `rackup` an optional dependency
dentarg Jan 2, 2024
1377751
Skip "without rackup" test on rack head branch
dentarg Jan 3, 2024
985625d
Fix `test_app_start_without_rackup` on JVM rubies
dentarg Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make rackup an optional dependency
  • Loading branch information
dentarg committed Jan 5, 2024
commit 8a78d8b337e77cffbfa34849a2c53ac380e64808
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.swp
*.rbc
/pkg
/Gemfile.lock
*.lock
/coverage
.yardoc
/doc
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rack_version = ENV['rack'].to_s
rack_version = nil if rack_version.empty? || (rack_version == 'stable')
rack_version = { github: 'rack/rack' } if rack_version == 'head'
gem 'rack', rack_version
gem 'rackup'

puma_version = ENV['puma'].to_s
puma_version = nil if puma_version.empty? || (puma_version == 'stable')
Expand Down
22 changes: 21 additions & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

# external dependencies
require 'rack'
require 'rackup'
begin
require 'rackup'
rescue LoadError
end
require 'tilt'
require 'rack/protection'
require 'mustermann'
Expand Down Expand Up @@ -1597,6 +1600,23 @@ def quit!
# Puma, Falcon, or WEBrick (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!

Add it to your bundle with:

bundle add rackup

or install it with:

gem install rackup

MISSING_RACKUP
warn rackup_warning
exit 1
end

return if running?

set options
Expand Down
1 change: 0 additions & 1 deletion sinatra.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ RubyGems 2.0 or newer is required to protect against public gem pushes. You can

s.add_dependency 'mustermann', '~> 3.0'
s.add_dependency 'rack', '>= 3.0.0', '< 4'
s.add_dependency 'rackup', '>= 2.0.0', '< 3'
s.add_dependency 'rack-protection', version
s.add_dependency 'tilt', '~> 2.0'
end
5 changes: 5 additions & 0 deletions test/integration/gemfile_without_rackup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec path: File.join('..', '..')
7 changes: 5 additions & 2 deletions test/integration_start_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def command_for(app_file)
]
end

def with_process(command)
def with_process(command:, env: {}, debug: false)
process = ChildProcess.build(*command)
process.leader = true # ensure entire process tree dies
process.environment.merge!(env)
read_io, write_io = IO.pipe
process.io.stdout = write_io
process.io.stderr = write_io
Expand All @@ -27,6 +28,8 @@ def with_process(command)
# will not detect EOF.
write_io.close

echo_output(read_io) if debug || debug_all?

yield process, read_io
ensure
read_io.close
Expand All @@ -42,7 +45,7 @@ def echo_output(read_io)
end
end

def debug?
def debug_all?
ENV.key?("DEBUG_START_PROCESS")
end

Expand Down
17 changes: 13 additions & 4 deletions test/integration_start_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
class IntegrationStartTest < Minitest::Test
include IntegrationStartHelper

def test_app_start_without_rackup
app_file = File.join(__dir__, "integration", "simple_app.rb")
gem_file = File.join(__dir__, "integration", "gemfile_without_rackup.rb")
command = command_for(app_file)
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/)
end
end

def test_classic_app_start
app_file = File.join(__dir__, "integration", "simple_app.rb")
command = command_for(app_file)
with_process(command) do |process, read_io|
echo_output(read_io) if debug? # will block
with_process(command: command) do |process, read_io|
assert wait_for_output(read_io, /Sinatra \(v.+\) has taken the stage/)
end
end

def test_classic_app_with_zeitwerk
app_file = File.join(__dir__, "integration", "zeitwerk_app.rb")
command = command_for(app_file)
with_process(command) do |process, read_io|
echo_output(read_io) if debug? # will block
with_process(command: command) do |process, read_io|
assert wait_for_output(read_io, /Sinatra \(v.+\) has taken the stage/)
end
end
Expand Down