diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2015-10-01 21:54:18 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2015-10-01 21:54:18 -0700 |
commit | 9db73a2591e43d1851411727d6594a72efa35663 (patch) | |
tree | 9f0e05dcb3ab35af42fc3db13214046074895653 /actionpack/lib/action_dispatch/http/response.rb | |
parent | dd57f60de92833e4f934aad07d8dc5acb5fbbe16 (diff) | |
parent | 28a1a39967ada924179d080b9cd69b3c90f44e4a (diff) | |
download | rails-9db73a2591e43d1851411727d6594a72efa35663.tar.gz rails-9db73a2591e43d1851411727d6594a72efa35663.tar.bz2 rails-9db73a2591e43d1851411727d6594a72efa35663.zip |
Merge pull request #21838 from jeremy/response-add-header
Response#add_header for adding to multi-valued headers like Vary
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 20 |
1 files changed, 20 insertions, 0 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 } |