aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-09-24 13:31:33 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-09-24 13:54:42 -0700
commit9a1ca78d34b6a8687af4f6f00cca8005f144a399 (patch)
tree0d25ff366fb5066c491cc3e4814845061d9ef4d5 /actionpack
parentfcf5e178dd6384cb5f9e99c0026ba958e426a03f (diff)
downloadrails-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')
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb23
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: