aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb20
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb4
2 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 85d9c3be00..f6f63f1f32 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -161,6 +161,26 @@ module ActionDispatch # :nodoc:
def set_header(key, v); headers[key] = v; end
def delete_header(key); headers.delete key; end
+ # Add a header that may have multiple values.
+ #
+ # Example:
+ # response.add_header 'Vary', 'Accept'
+ # response.add_header 'Vary', 'Accept-Encoding'
+ # response.add_header 'Vary', 'Cookie'
+ #
+ # assert_equal 'Accept,Accept-Encoding,Cookie', response.get_header 'Vary'
+ #
+ # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
+ def add_header(key, v)
+ if v.nil?
+ get_header key
+ elsif have_header? key
+ set_header key, "#{get_header key},#{v}"
+ else
+ set_header key, v
+ end
+ end
+
def await_commit
synchronize do
@cv.wait_until { @committed }
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 7ed77352ae..2889acaeb8 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -396,7 +396,9 @@ module ActionDispatch
end
def write(headers)
- headers[HTTP_HEADER] = make_set_cookie_header headers[HTTP_HEADER]
+ if header = make_set_cookie_header(headers[HTTP_HEADER])
+ headers[HTTP_HEADER] = header
+ end
end
mattr_accessor :always_write_cookie