diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-24 13:31:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-24 13:54:42 -0700 |
commit | 9a1ca78d34b6a8687af4f6f00cca8005f144a399 (patch) | |
tree | 0d25ff366fb5066c491cc3e4814845061d9ef4d5 /actionpack/lib/action_dispatch/middleware | |
parent | fcf5e178dd6384cb5f9e99c0026ba958e426a03f (diff) | |
download | rails-9a1ca78d34b6a8687af4f6f00cca8005f144a399.tar.gz rails-9a1ca78d34b6a8687af4f6f00cca8005f144a399.tar.bz2 rails-9a1ca78d34b6a8687af4f6f00cca8005f144a399.zip |
build the Set-Cookie header functionally
Use the Rack utility methods for functional header manipulation. This
helps to eliminate coupling on the header hash
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index b653e4eacd..7ed77352ae 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -396,17 +396,30 @@ module ActionDispatch end def write(headers) - @set_cookies.each { |k, v| ::Rack::Utils.set_cookie_header!(headers, k, v) if write_cookie?(v) } - @delete_cookies.each { |k, v| ::Rack::Utils.delete_cookie_header!(headers, k, v) } + headers[HTTP_HEADER] = make_set_cookie_header headers[HTTP_HEADER] end mattr_accessor :always_write_cookie self.always_write_cookie = false private - def write_cookie?(cookie) - request.ssl? || !cookie[:secure] || always_write_cookie - end + + def make_set_cookie_header(header) + header = @set_cookies.inject(header) { |m, (k, v)| + if write_cookie?(v) + ::Rack::Utils.add_cookie_to_header(m, k, v) + else + m + end + } + @delete_cookies.inject(header) { |m, (k, v)| + ::Rack::Utils.add_remove_cookie_to_header(m, k, v) + } + end + + def write_cookie?(cookie) + request.ssl? || !cookie[:secure] || always_write_cookie + end end class AbstractCookieJar # :nodoc: |