Permalink
Browse files

Fix case when Set-Cookie header is nil

  • Loading branch information...
1 parent 75d94d0 commit c9579dbd9df22ddbaab6cf3ae271a0b8b37d8277 @josh josh committed Nov 4, 2010
Showing with 17 additions and 8 deletions.
  1. +9 −8 lib/rack/ssl.rb
  2. +8 −0 test/test_ssl.rb
View
@@ -58,14 +58,15 @@ def hsts_headers
end
def flag_cookies_as_secure!(headers)
- cookies = headers['Set-Cookie'].split("\n")
- headers['Set-Cookie'] = cookies.map { |cookie|
- if cookie !~ / secure;/
- "#{cookie}; secure"
- else
- cookie
- end
- }.join("\n")
+ if cookies = headers['Set-Cookie']
+ headers['Set-Cookie'] = cookies.split("\n").map { |cookie|
+ if cookie !~ / secure;/
+ "#{cookie}; secure"
+ else
+ cookie
+ end
+ }.join("\n")
+ end
end
end
end
View
@@ -74,4 +74,12 @@ def test_flag_cookies_as_secure
assert_equal ["id=1; path=/; secure", "token=abc; path=/; secure; HttpOnly"],
last_response.headers['Set-Cookie'].split("\n")
end
+
+ def test_no_cookies
+ self.app = Rack::SSL.new(lambda { |env|
+ [200, {'Content-Type' => "text/html"}, ["OK"]]
+ })
+ get "https://example.org/"
+ assert !last_response.headers['Set-Cookie']
+ end
end

0 comments on commit c9579db

Please sign in to comment.