Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Properly receive cookies on redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
bragi committed Dec 31, 2010
1 parent c3c5fbc commit 64ae604
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/cookie-spec.coffee
Expand Up @@ -17,6 +17,9 @@ brains.get "/cookies", (req, res)->
brains.get "/cookies/echo", (req,res)->
cookies = ("#{k}=#{v}" for k,v of req.cookies).join("; ")
res.send "<html>#{cookies}</html>"
brains.get "/cookies_redirect", (req, res)->
res.cookie "_expires5", "3s", "Expires": new Date(Date.now() + 3000), "Path": "/"
res.redirect "/"

vows.describe("Cookies").addBatch(
"get cookies":
Expand Down Expand Up @@ -60,6 +63,14 @@ vows.describe("Cookies").addBatch(
assert.equal pairs._name, "value"
assert.equal pairs._path1, "yummy"

"get cookies and redirect":
zombie.wants "http://localhost:3003/cookies_redirect"
"cookies":
topic: (browser)->
browser.cookies("localhost", "/")
"should have access to persistent cookie": (cookies)->
assert.equal cookies.get("_expires5"), "3s"

"send cookies":
topic: ->
browser = new zombie.Browser()
Expand Down
1 change: 1 addition & 0 deletions src/zombie/history.coffee
Expand Up @@ -113,6 +113,7 @@ class History
else
error = "Could not parse document at #{URL.format(url)}"
when 301, 302, 303, 307
browser.cookies(url.hostname, url.pathname).update response.headers["set-cookie"]
redirect = URL.parse(URL.resolve(url, response.headers["location"]))
stack[index] = new Entry(this, redirect)
browser.emit "redirected", redirect
Expand Down

0 comments on commit 64ae604

Please sign in to comment.