Sha256: 2b1846aa5047e9d6a8eb3a48af56dfdbfb9c53044eb28a7b8ca1a928c311f1be

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

/*!
 * cookie-parser
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var cookie = require('cookie');
var parse = require('./lib/parse');

/**
 * Parse Cookie header and populate `req.cookies`
 * with an object keyed by the cookie names.
 *
 * @param {String} [secret]
 * @param {Object} [options]
 * @return {Function}
 * @api public
 */

exports = module.exports = function cookieParser(secret, options){
  return function cookieParser(req, res, next) {
    if (req.cookies) return next();
    var cookies = req.headers.cookie;

    req.secret = secret;
    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 (secret) {
      req.signedCookies = parse.signedCookies(req.cookies, secret);
      req.signedCookies = parse.JSONCookies(req.signedCookies);
    }

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

    next();
  };
};

/**
 * Export parsing functions.
 */

exports.JSONCookie = parse.JSONCookie;
exports.JSONCookies = parse.JSONCookies;
exports.signedCookie = parse.signedCookie;
exports.signedCookies = parse.signedCookies;

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/cookie-parser/index.js