Skip to content

Commit

Permalink
Merge pull request rack#231 from lawrencepit/cookies
Browse files Browse the repository at this point in the history
Request should return cookies, also when initially not set.
  • Loading branch information
raggi committed Sep 16, 2011
2 parents d099ea0 + 02209e2 commit 1b7f7af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Expand Up @@ -250,8 +250,8 @@ def cookies
hash = @env["rack.request.cookie_hash"] ||= {}
string = @env["HTTP_COOKIE"]

hash.clear unless string
return hash if string == @env["rack.request.cookie_string"]
hash.clear

# According to RFC 2109:
# If multiple cookies satisfy the criteria above, they are ordered in
Expand Down
9 changes: 9 additions & 0 deletions test/spec_request.rb
Expand Up @@ -357,6 +357,15 @@
hash = req.cookies
req.env.delete("HTTP_COOKIE")
req.cookies.should.equal(hash)
req.env["HTTP_COOKIE"] = "zoo=m"
req.cookies.should.equal(hash)
end

should "modify the cookies hash in place" do
req = Rack::Request.new(Rack::MockRequest.env_for(""))
req.cookies.should.equal({})
req.cookies['foo'] = 'bar'
req.cookies.should.equal 'foo' => 'bar'
end

should "raise any errors on every request" do
Expand Down

0 comments on commit 1b7f7af

Please sign in to comment.