index.js
function cookieParser (secret, options) {
  var secrets = !secret || Array.isArray(secret)
    ? (secret || [])
    : [secret]

  return function cookieParser (req, res, next) {
    if (req.cookies) {
      return next()
    }

    var cookies = req.headers.cookie

    req.secret = secrets[0]
    req.cookies = Object.create(null)
    req.signedCookies = Object.create(null)

    // no cookies
    if (!cookies) {
      return next()
    }

    req.cookies = cookie.parse(cookies, options)

    // parse signed cookies
    if (secrets.length !== 0) {
      req.signedCookies = signedCookies(req.cookies, secrets)
      req.signedCookies = JSONCookies(req.signedCookies)
    }

    // parse JSON cookies
    req.cookies = JSONCookies(req.cookies)

    next()
  }
}
function cookieParser (secret, options) {
  var secrets = !secret || Array.isArray(secret)
    ? (secret || [])
    : [secret]

  return function cookieParser (req, res, next) {
    if (req.cookies) {
      return next()
    }

    var cookies = req.headers.cookie

    req.secret = secrets[0]
    req.cookies = Object.create(null)
    req.signedCookies = Object.create(null)

    // no cookies
    if (!cookies) {
      return next()
    }

    req.cookies = cookie.parse(cookies, options)

    // parse signed cookies
    if (secrets.length !== 0) {
      req.signedCookies = signedCookies(req.cookies, secrets)
      req.signedCookies = JSONCookies(req.signedCookies)
    }

    // parse JSON cookies
    req.cookies = JSONCookies(req.cookies)

    next()
  }
}
function cookieParser ( secret , options ) { var secrets = ! secret || Array . isArray ( secret ) ? ( secret || [ ] ) : [ secret ] return function cookieParser ( req , res , next ) { if ( req . cookies ) { return next ( ) } var cookies = req . headers . cookie req . secret = secrets [ 0 ] req . cookies = Object . create ( null ) req . signedCookies = Object . create ( null ) // no cookies if ( ! cookies ) { return next ( ) } req . cookies = cookie . parse ( cookies , options ) // parse signed cookies if ( secrets . length !== 0 ) { req . signedCookies = signedCookies ( req . cookies , secrets ) req . signedCookies = JSONCookies ( req . signedCookies ) } // parse JSON cookies req . cookies = JSONCookies ( req . cookies ) next ( ) } }
Parse Cookie header and populate `req.cookies`
with an object keyed by the cookie names.

@param {string|array} [secret] A string (or array of strings) representing cookie signing secret(s).
@param {Object} [options]
@return {Function}
@public
Parse Cookie header and populate req . cookies with an object keyed by the cookie names .