Permalink
Browse files

whitespace housekeeping

  • Loading branch information...
1 parent d672f51 commit d68e51c36c21f39b6ff26104ced40a9701808b2a @jed jed committed Apr 25, 2012
Showing with 53 additions and 53 deletions.
  1. +53 −53 lib/cookies.js
View
@@ -1,75 +1,75 @@
var cache = {}
-function Cookies( request, response, keys ) {
+function Cookies(request, response, keys) {
this.request = request
this.response = response
this.keys = keys
}
Cookies.prototype = {
- get: function( name, opts ) {
+ 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
-
- match = header.match( getPattern( name ) )
- if ( !match ) return
-
- value = match[ 1 ]
- if ( !opts || !signed ) return value
-
- remote = this.get( sigName )
- if ( !remote ) return
-
- data = name + "=" + value
- index = this.keys.index( data, remote )
-
- if ( index < 0 ) this.set( sigName, null, { path: "/" } )
-
+
+ header = this.request.headers["cookie"]
+ if (!header) return
+
+ match = header.match(getPattern(name))
+ if (!match) return
+
+ value = match[1]
+ if (!opts || !signed) return value
+
+ remote = this.get(sigName)
+ if (!remote) return
+
+ data = name + "=" + value
+ index = this.keys.index(data, remote)
+
+ if (index < 0) this.set(sigName, null, {path: "/"})
+
else {
- index && this.set( sigName, this.keys.sign( data ) )
+ index && this.set(sigName, this.keys.sign(data))
return value
}
},
-
- set: function( name, value, opts ) {
+
+ set: function(name, value, opts) {
var res = this.response
, req = this.request
- , headers = res.getHeader( "Set-Cookie" ) || []
+ , headers = res.getHeader("Set-Cookie") || []
, secure = res.socket ? res.socket.encrypted || req.connection.proxySecure : req.connection.proxySecure
- , cookie = new Cookie( name, value, opts )
+ , cookie = new Cookie(name, value, opts)
, header
, signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
-
- if ( typeof headers == "string" ) headers = [ headers ]
-
- if ( !secure && opts && opts.secure ) throw "Cannot send secure cookie over unencrypted socket"
-
+
+ if (typeof headers == "string") headers = [headers]
+
+ if (!secure && opts && opts.secure) throw "Cannot send secure cookie over unencrypted socket"
+
cookie.secure = secure
if (opts && "secure" in opts) cookie.secure = opts.secure
- headers.push( cookie.toHeader() )
-
- if ( opts && signed ) {
- cookie.value = this.keys.sign( cookie.toString() )
+ headers.push(cookie.toHeader())
+
+ if (opts && signed) {
+ cookie.value = this.keys.sign(cookie.toString())
cookie.name += ".sig"
- headers.push( cookie.toHeader() )
+ headers.push(cookie.toHeader())
}
- res.setHeader( "Set-Cookie", headers )
+ res.setHeader("Set-Cookie", headers)
return this
}
}
-function Cookie( name, value, attrs ) {
- value || ( this.expires = new Date( 0 ) )
+function Cookie(name, value, attrs) {
+ value || (this.expires = new Date(0))
this.name = name
this.value = value || ""
- for ( var name in attrs ) this[ name ] = attrs[ name ]
+ for (var name in attrs) this[name] = attrs[name]
}
Cookie.prototype = {
@@ -79,27 +79,27 @@ Cookie.prototype = {
httpOnly: true,
secure: false,
- toString: function() { return this.name + "=" + this.value },
-
+ toString: function() {return this.name + "=" + this.value},
+
toHeader: function() {
var header = this.toString()
-
- if ( this.path ) header += "; path=" + this.path
- if ( this.expires ) header += "; expires=" + this.expires.toUTCString()
- if ( this.domain ) header += "; domain=" + this.domain
- if ( this.secure ) header += "; secure"
- if ( this.httpOnly ) header += "; httponly"
-
+
+ if (this.path ) header += "; path=" + this.path
+ if (this.expires ) header += "; expires=" + this.expires.toUTCString()
+ if (this.domain ) header += "; domain=" + this.domain
+ if (this.secure ) header += "; secure"
+ if (this.httpOnly ) header += "; httponly"
+
return header
}
}
-function getPattern( name ) {
- if ( cache[ name ] ) return cache[ name ]
-
- return cache[ name ] = new RegExp(
+function getPattern(name) {
+ if (cache[name]) return cache[name]
+
+ return cache[name] = new RegExp(
"(?:^|;) *" +
- name.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&" ) +
+ name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") +
"=([^;]*)"
)
}

0 comments on commit d68e51c

Please sign in to comment.