aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-05-18 01:42:35 +0200
committerJosé Valim <jose.valim@gmail.com>2010-05-18 01:51:45 +0200
commit941b653627b9ca7b7f2ddb4a712fb0efccc10500 (patch)
tree84fbdd7b30f2e4eab2e76e420b6f9c392de16c4f
parent8c5e1652c7d1343a4b4acbc10bbcb59e202bf37d (diff)
downloadrails-941b653627b9ca7b7f2ddb4a712fb0efccc10500.tar.gz
rails-941b653627b9ca7b7f2ddb4a712fb0efccc10500.tar.bz2
rails-941b653627b9ca7b7f2ddb4a712fb0efccc10500.zip
Rely on set and delete cookie logic from rack.
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb35
-rw-r--r--actionpack/test/dispatch/response_test.rb4
2 files changed, 6 insertions, 33 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 8b730a97ee..3b85a98576 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -140,7 +140,7 @@ module ActionDispatch # :nodoc:
def to_a
assign_default_content_type_and_charset!
handle_conditional_get!
- self["Set-Cookie"] = @cookie.join("\n") unless @cookie.blank?
+ self["Set-Cookie"] = self["Set-Cookie"].join("\n") if self["Set-Cookie"].respond_to?(:join)
self["ETag"] = @_etag if @_etag
super
end
@@ -170,7 +170,7 @@ module ActionDispatch # :nodoc:
# assert_equal 'AuthorOfNewPage', r.cookies['author']
def cookies
cookies = {}
- if header = @cookie
+ if header = self["Set-Cookie"]
header = header.split("\n") if header.respond_to?(:to_str)
header.each do |cookie|
if pair = cookie.split(';').first
@@ -182,37 +182,6 @@ module ActionDispatch # :nodoc:
cookies
end
- def set_cookie(key, value)
- case value
- when Hash
- domain = "; domain=" + value[:domain] if value[:domain]
- path = "; path=" + value[:path] if value[:path]
- # According to RFC 2109, we need dashes here.
- # N.B.: cgi.rb uses spaces...
- expires = "; expires=" + value[:expires].clone.gmtime.
- strftime("%a, %d-%b-%Y %H:%M:%S GMT") if value[:expires]
- secure = "; secure" if value[:secure]
- httponly = "; HttpOnly" if value[:httponly]
- value = value[:value]
- end
- value = [value] unless Array === value
- cookie = Rack::Utils.escape(key) + "=" +
- value.map { |v| Rack::Utils.escape v }.join("&") +
- "#{domain}#{path}#{expires}#{secure}#{httponly}"
-
- @cookie << cookie
- end
-
- def delete_cookie(key, value={})
- @cookie.reject! { |cookie|
- cookie =~ /\A#{Rack::Utils.escape(key)}=/
- }
-
- set_cookie(key,
- {:value => '', :path => nil, :domain => nil,
- :expires => Time.at(0) }.merge(value))
- end
-
private
def assign_default_content_type_and_charset!
return if headers[CONTENT_TYPE].present?
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index c7f7f3102d..c20fa10f63 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -113,6 +113,10 @@ class ResponseTest < ActiveSupport::TestCase
status, headers, body = @response.to_a
assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"]
assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies)
+
+ @response.delete_cookie("login")
+ status, headers, body = @response.to_a
+ assert_equal({"user_name" => "david", "login" => nil}, @response.cookies)
end
test "read cache control" do