Skip to content

Commit

Permalink
Fix #10 Default signedness based on presence of keys
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 25, 2012
1 parent d55bf43 commit b1322b6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/cookies.js
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 ]

Expand All @@ -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() )
Expand Down Expand Up @@ -109,4 +111,4 @@ Cookies.connect = Cookies.express = function(keys) {
}
}

module.exports = Cookies
module.exports = Cookies

0 comments on commit b1322b6

Please sign in to comment.