diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-08-20 20:23:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-20 20:23:25 +0200 |
commit | cdcd6c0945ad8b6c67a148634ae023689bdd6077 (patch) | |
tree | d8262178a283326a493d394fa104745437cb6562 /actionpack/lib | |
parent | 84f5627c5ef3271a27c11253928b5895bf7f7f6b (diff) | |
parent | 5f37e16ab5fb36555175379ad96b2da3c3b31a0b (diff) | |
download | rails-cdcd6c0945ad8b6c67a148634ae023689bdd6077.tar.gz rails-cdcd6c0945ad8b6c67a148634ae023689bdd6077.tar.bz2 rails-cdcd6c0945ad8b6c67a148634ae023689bdd6077.zip |
Merge pull request #30121 from assain/add_expires_in_and_expires_at_to_cookies
Add expiry metadata to Cookies and freshen expires option to support duration
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 5a55ee13ee..c0913715ac 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -360,7 +360,11 @@ module ActionDispatch @cookies.map { |k, v| "#{escape(k)}=#{escape(v)}" }.join "; " end - def handle_options(options) #:nodoc: + def handle_options(options) # :nodoc: + if options[:expires].respond_to?(:from_now) + options[:expires] = options[:expires].from_now + end + options[:path] ||= "/" if options[:domain] == :all || options[:domain] == "all" @@ -488,6 +492,14 @@ module ActionDispatch def request; @parent_jar.request; end private + def expiry_options(options) + if options[:expires].respond_to?(:from_now) + { expires_in: options[:expires] } + else + { expires_at: options[:expires] } + end + end + def parse(name, data); data; end def commit(options); end end @@ -569,7 +581,7 @@ module ActionDispatch end def commit(options) - options[:value] = @verifier.generate(serialize(options[:value])) + options[:value] = @verifier.generate(serialize(options[:value]), expiry_options(options)) raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE end @@ -609,7 +621,7 @@ module ActionDispatch end def commit(options) - options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value])) + options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value]), expiry_options(options)) raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE end |