-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cookie-jar dependency for ruby 3.3 (#2395)
* Remove cookie-jar dependency Remove deleted and set max-age 0 for current cookies Replace HTTP_COOKIE by set-cookie function Replace Set-Cookie by Rack::SET_COOKIE Update specs * Remove delete_set_cookie_header and set_cookie_header since its in rack >= 3.0 * Add cookie_helper to manage different expires value. * Fix rubocop * Add cookiejar to Rack::MockResponse * Add CHANGELOG.md entry * Update CHANGELOG.md * Fix CHANGELOG.md
- Loading branch information
1 parent
63a0416
commit 15c891c
Showing
18 changed files
with
86 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
describe Grape::API do | ||
subject do | ||
puts described_class | ||
Class.new(described_class) | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uri' | ||
|
||
module Rack | ||
class MockResponse | ||
def cookie_jar | ||
@cookie_jar ||= Array(headers['Set-Cookie']).flat_map { |h| h.split("\n") }.map { |c| Cookie.new(c).to_h } | ||
end | ||
|
||
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie | ||
class Cookie | ||
attr_reader :attributes | ||
|
||
def initialize(raw) | ||
@attributes = raw.split(/;\s*/).flat_map.with_index do |attribute, i| | ||
attribute, value = attribute.split('=', 2) | ||
if i.zero? | ||
[['name', attribute], ['value', unescape(value)]] | ||
else | ||
[[attribute.downcase, parse_value(attribute, value)]] | ||
end | ||
end.to_h.freeze | ||
end | ||
|
||
def to_h | ||
@attributes.dup | ||
end | ||
|
||
def to_s | ||
@attributes.to_s | ||
end | ||
|
||
private | ||
|
||
def unescape(value) | ||
URI.decode_www_form_component(value, Encoding::UTF_8) | ||
end | ||
|
||
def parse_value(attribute, value) | ||
case attribute | ||
when 'expires' | ||
Time.parse(value) | ||
when 'max-age' | ||
value.to_i | ||
when 'secure', 'httponly', 'partitioned' | ||
true | ||
else | ||
unescape(value) | ||
end | ||
end | ||
end | ||
end | ||
end |