Permalink
Browse files

Merge pull request #11 from isaacs/master

Fix #10 Default signedness based on presence of keys
  • Loading branch information...
2 parents d55bf43 + b1322b6 commit d672f519f0ee73c68fc5884e6ae8447054fed86d @jed jed committed Apr 25, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/cookies.js
View
@@ -10,6 +10,7 @@ Cookies.prototype = {
get: function( name, opts ) {
var sigName = name + ".sig"
, header, match, value, remote, data, index
+ , signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
header = this.request.headers[ "cookie" ]
if ( !header ) return
@@ -18,7 +19,7 @@ Cookies.prototype = {
if ( !match ) return
value = match[ 1 ]
- if ( !opts || !opts.signed ) return value
+ if ( !opts || !signed ) return value
remote = this.get( sigName )
if ( !remote ) return
@@ -41,6 +42,7 @@ Cookies.prototype = {
, secure = res.socket ? res.socket.encrypted || req.connection.proxySecure : req.connection.proxySecure
, cookie = new Cookie( name, value, opts )
, header
+ , signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
if ( typeof headers == "string" ) headers = [ headers ]
@@ -50,7 +52,7 @@ Cookies.prototype = {
if (opts && "secure" in opts) cookie.secure = opts.secure
headers.push( cookie.toHeader() )
- if ( opts && opts.signed ) {
+ if ( opts && signed ) {
cookie.value = this.keys.sign( cookie.toString() )
cookie.name += ".sig"
headers.push( cookie.toHeader() )
@@ -109,4 +111,4 @@ Cookies.connect = Cookies.express = function(keys) {
}
}
-module.exports = Cookies
+module.exports = Cookies

0 comments on commit d672f51

Please sign in to comment.