Skip to content

Commit

Permalink
Use Cookie.parse
Browse files Browse the repository at this point in the history
Using new Cookie(str) doesn't actually set the attributes in the cookie.
This is because Cookie takes in an object, and in our case we only
accept a string. Using Cookie.parse will return the appropriate
properties for the cookie.
  • Loading branch information
lalitkapoor committed Dec 23, 2013
1 parent d98c94d commit 41e20a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ request.jar = function () {
request.cookie = function (str) {
if (str && str.uri) str = str.uri
if (typeof str !== 'string') throw new Error("The cookie function only accepts STRING as param")
return new Cookie(str)
return Cookie.parse(str)
}
19 changes: 19 additions & 0 deletions tests/test-cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try {
require('tough-cookie')
} catch (e) {
console.error('tough-cookie must be installed to run this test.')
console.error('skipping this test. please install tough-cookie and run again if you need to test this feature.')
process.exit(0)
}

var assert = require('assert')
, request = require('../index')


function simpleCookieCreationTest() {
var cookie = request.cookie('foo=bar')
assert(cookie.key === 'foo')
assert(cookie.value === 'bar')
}

simpleCookieCreationTest()

0 comments on commit 41e20a4

Please sign in to comment.