From 09e81c7069341ab219ddbd74817feea4a09b8172 Mon Sep 17 00:00:00 2001 From: Jesse Storimer Date: Tue, 1 Jun 2010 08:35:25 -0400 Subject: [PATCH] CookieStore should preserve the Set-Cookie header Array [#4743 state:resolved] --- .../lib/action_controller/session/cookie_store.rb | 7 ++----- .../test/controller/session/cookie_store_test.rb | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/actionpack/lib/action_controller/session/cookie_store.rb b/actionpack/lib/action_controller/session/cookie_store.rb index 3d21e81..2fcee56 100644 --- a/actionpack/lib/action_controller/session/cookie_store.rb +++ b/actionpack/lib/action_controller/session/cookie_store.rb @@ -114,11 +114,8 @@ module ActionController end cookie = build_cookie(@key, cookie.merge(options)) - unless headers[HTTP_SET_COOKIE].blank? - headers[HTTP_SET_COOKIE] << "\n#{cookie}" - else - headers[HTTP_SET_COOKIE] = cookie - end + headers[HTTP_SET_COOKIE] = [] if headers[HTTP_SET_COOKIE].blank? + headers[HTTP_SET_COOKIE] << cookie end [status, headers, body] diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 5ef8eec..02e9ed2 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -44,6 +44,12 @@ class CookieStoreTest < ActionController::IntegrationTest head :ok end + def set_session_value_and_cookie + cookies["foo"] = "bar" + session[:foo] = "bar" + render :text => Rack::Utils.escape(Verifier.generate(session.to_hash)) + end + def rescue_action(e) raise end end @@ -96,7 +102,7 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", + assert_equal ["_myapp_session=#{response.body}; path=/; HttpOnly"], headers['Set-Cookie'] end end @@ -164,7 +170,7 @@ class CookieStoreTest < ActionController::IntegrationTest get '/set_session_value' assert_response :success session_payload = response.body - assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly", + assert_equal ["_myapp_session=#{response.body}; path=/; HttpOnly"], headers['Set-Cookie'] get '/call_reset_session' @@ -193,6 +199,14 @@ class CookieStoreTest < ActionController::IntegrationTest end end + def test_setting_session_value_and_cookie + with_test_route_set do + get '/set_session_value_and_cookie' + assert_response :success + assert_equal({"_myapp_session" => response.body, "foo" => "bar"}, cookies) + end + end + private def with_test_route_set with_routing do |set| -- 1.7.1