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
sinatra-contrib tests now pass
Multiple response header values are encoded using an Array instead of
newlines: https://github.com/rack/rack/blob/v3.0.3/UPGRADE-GUIDE.md#multiple-response-header-values-are-encoded-using-an-array

Rack 3 does not remove cookies from the internal storage (because it
doesn't make much sense), see rack/rack#1844, rack/rack#1840
  • Loading branch information
dentarg committed Jan 5, 2024
commit 0a9b043a24b2cb57a2a8e23a0814afb74c17485e
10 changes: 5 additions & 5 deletions sinatra-contrib/lib/sinatra/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Jar
attr_reader :options

def initialize(app)
@response_string = nil
@response_array = nil
@response_hash = {}
@response = app.response
@request = app.request
Expand Down Expand Up @@ -309,12 +309,12 @@ def response_cookies
end

def parse_response
string = @response['Set-Cookie']
return if @response_string == string
cookies_from_response = Array(@response['Set-Cookie'])
return if @response_array == cookies_from_response

hash = {}

string.each_line do |line|
cookies_from_response.each do |line|
key, value = line.split(';', 2).first.to_s.split('=', 2)
next if key.nil?

Expand All @@ -328,7 +328,7 @@ def parse_response
end

@response_hash.replace hash
@response_string = string
@response_array = cookies_from_response
end

def request_cookies
Expand Down
25 changes: 14 additions & 11 deletions sinatra-contrib/spec/cookies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def cookies(*set_cookies)
expect(jar['foo']).to be_nil
end

it 'removes response cookies from cookies hash' do
it 'does not remove response cookies from cookies hash' do
expect(cookie_route do
cookies['foo'] = 'bar'
cookies.clear
cookies['foo']
end).to be_nil
end).to eq('bar')
end

it 'expires existing cookies' do
Expand Down Expand Up @@ -189,12 +189,12 @@ def cookies(*set_cookies)
expect(jar['foo']).to be_nil
end

it 'removes response cookies from cookies hash' do
it 'does not remove response cookies from cookies hash' do
expect(cookie_route do
cookies['foo'] = 'bar'
cookies.delete 'foo'
cookies['foo']
end).to be_nil
end).to eq('bar')
end

it 'expires existing cookies' do
Expand Down Expand Up @@ -246,13 +246,16 @@ def cookies(*set_cookies)
end

describe :delete_if do
it 'deletes cookies that match the block' do
it 'expires cookies that match the block' do
expect(cookie_route('foo=bar') do
cookies['bar'] = 'baz'
cookies['baz'] = 'foo'
cookies.delete_if { |*a| a.include? 'bar' }
cookies.values_at 'foo', 'bar', 'baz'
end).to eq([nil, nil, 'foo'])
response['Set-Cookie']
end).to eq(["bar=baz; domain=example.org; path=/; httponly",
"baz=foo; domain=example.org; path=/; httponly",
"foo=; domain=example.org; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT; httponly",
"bar=; domain=example.org; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT; httponly"])
end
end

Expand Down Expand Up @@ -454,12 +457,12 @@ def cookies(*set_cookies)
end).to be false
end

it 'becomes true if response cookies are removed' do
it 'deos not become true if response cookies are removed' do
dentarg marked this conversation as resolved.
Show resolved Hide resolved
expect(cookie_route do
cookies['foo'] = 'bar'
cookies.delete :foo
cookies.empty?
end).to be true
end).to be false
end

it 'becomes true if request cookies are removed' do
Expand All @@ -469,12 +472,12 @@ def cookies(*set_cookies)
end).to be_truthy
end

it 'becomes true after clear' do
it 'does not become true after clear' do
expect(cookie_route('foo=bar', 'bar=baz') do
cookies['foo'] = 'bar'
cookies.clear
cookies.empty?
end).to be_truthy
end).to be false
end
end

Expand Down
2 changes: 1 addition & 1 deletion sinatra-contrib/spec/link_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
describe :link do
it "sets link headers" do
get '/'
expect(headers['Link'].lines).to include('<booyah>; rel="something"')
expect(headers['Link']).to include('<booyah>; rel="something"')
end

it "returns link html tags" do
Expand Down