/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['middleware/cookieSession.js']) {
  _$jscoverage['middleware/cookieSession.js'] = [];
  _$jscoverage['middleware/cookieSession.js'][12] = 0;
  _$jscoverage['middleware/cookieSession.js'][46] = 0;
  _$jscoverage['middleware/cookieSession.js'][48] = 0;
  _$jscoverage['middleware/cookieSession.js'][49] = 0;
  _$jscoverage['middleware/cookieSession.js'][52] = 0;
  _$jscoverage['middleware/cookieSession.js'][55] = 0;
  _$jscoverage['middleware/cookieSession.js'][56] = 0;
  _$jscoverage['middleware/cookieSession.js'][59] = 0;
  _$jscoverage['middleware/cookieSession.js'][60] = 0;
  _$jscoverage['middleware/cookieSession.js'][63] = 0;
  _$jscoverage['middleware/cookieSession.js'][66] = 0;
  _$jscoverage['middleware/cookieSession.js'][67] = 0;
  _$jscoverage['middleware/cookieSession.js'][70] = 0;
  _$jscoverage['middleware/cookieSession.js'][71] = 0;
  _$jscoverage['middleware/cookieSession.js'][72] = 0;
  _$jscoverage['middleware/cookieSession.js'][73] = 0;
  _$jscoverage['middleware/cookieSession.js'][74] = 0;
  _$jscoverage['middleware/cookieSession.js'][75] = 0;
  _$jscoverage['middleware/cookieSession.js'][80] = 0;
  _$jscoverage['middleware/cookieSession.js'][82] = 0;
  _$jscoverage['middleware/cookieSession.js'][83] = 0;
  _$jscoverage['middleware/cookieSession.js'][84] = 0;
  _$jscoverage['middleware/cookieSession.js'][85] = 0;
  _$jscoverage['middleware/cookieSession.js'][86] = 0;
  _$jscoverage['middleware/cookieSession.js'][89] = 0;
  _$jscoverage['middleware/cookieSession.js'][92] = 0;
  _$jscoverage['middleware/cookieSession.js'][97] = 0;
  _$jscoverage['middleware/cookieSession.js'][100] = 0;
  _$jscoverage['middleware/cookieSession.js'][101] = 0;
  _$jscoverage['middleware/cookieSession.js'][104] = 0;
  _$jscoverage['middleware/cookieSession.js'][107] = 0;
  _$jscoverage['middleware/cookieSession.js'][108] = 0;
  _$jscoverage['middleware/cookieSession.js'][109] = 0;
  _$jscoverage['middleware/cookieSession.js'][110] = 0;
  _$jscoverage['middleware/cookieSession.js'][113] = 0;
}
_$jscoverage['middleware/cookieSession.js'][12]++;
var utils = require("./../utils"), Cookie = require("./session/cookie"), debug = require("debug")("connect:cookieSession"), signature = require("cookie-signature"), crc16 = require("crc").crc16;
_$jscoverage['middleware/cookieSession.js'][46]++;
module.exports = (function cookieSession(options) {
  _$jscoverage['middleware/cookieSession.js'][48]++;
  options = options || {};
  _$jscoverage['middleware/cookieSession.js'][49]++;
  var key = options.key || "connect.sess", trustProxy = options.proxy;
  _$jscoverage['middleware/cookieSession.js'][52]++;
  return (function cookieSession(req, res, next) {
  _$jscoverage['middleware/cookieSession.js'][55]++;
  var secret = options.secret || req.secret;
  _$jscoverage['middleware/cookieSession.js'][56]++;
  if (! secret) {
    _$jscoverage['middleware/cookieSession.js'][56]++;
    throw new Error("`secret` option required for cookie sessions");
  }
  _$jscoverage['middleware/cookieSession.js'][59]++;
  req.session = {};
  _$jscoverage['middleware/cookieSession.js'][60]++;
  var cookie = req.session.cookie = new Cookie(options.cookie);
  _$jscoverage['middleware/cookieSession.js'][63]++;
  if (0 != req.originalUrl.indexOf(cookie.path)) {
    _$jscoverage['middleware/cookieSession.js'][63]++;
    return next();
  }
  _$jscoverage['middleware/cookieSession.js'][66]++;
  if (! options.secret && req.secret) {
    _$jscoverage['middleware/cookieSession.js'][67]++;
    req.session = req.signedCookies[key] || {};
  }
  else {
    _$jscoverage['middleware/cookieSession.js'][70]++;
    var rawCookie = req.cookies[key];
    _$jscoverage['middleware/cookieSession.js'][71]++;
    if (rawCookie) {
      _$jscoverage['middleware/cookieSession.js'][72]++;
      var unsigned = utils.parseSignedCookie(rawCookie, secret);
      _$jscoverage['middleware/cookieSession.js'][73]++;
      if (unsigned) {
        _$jscoverage['middleware/cookieSession.js'][74]++;
        var originalHash = crc16(unsigned);
        _$jscoverage['middleware/cookieSession.js'][75]++;
        req.session = utils.parseJSONCookie(unsigned) || {};
      }
    }
  }
  _$jscoverage['middleware/cookieSession.js'][80]++;
  res.on("header", (function () {
  _$jscoverage['middleware/cookieSession.js'][82]++;
  if (! req.session) {
    _$jscoverage['middleware/cookieSession.js'][83]++;
    debug("clear session");
    _$jscoverage['middleware/cookieSession.js'][84]++;
    cookie.expires = new Date(0);
    _$jscoverage['middleware/cookieSession.js'][85]++;
    res.setHeader("Set-Cookie", cookie.serialize(key, ""));
    _$jscoverage['middleware/cookieSession.js'][86]++;
    return;
  }
  _$jscoverage['middleware/cookieSession.js'][89]++;
  delete req.session.cookie;
  _$jscoverage['middleware/cookieSession.js'][92]++;
  var proto = (req.headers["x-forwarded-proto"] || "").toLowerCase(), tls = req.connection.encrypted || (trustProxy && "https" == proto), secured = cookie.secure && tls;
  _$jscoverage['middleware/cookieSession.js'][97]++;
  if (cookie.secure && ! secured) {
    _$jscoverage['middleware/cookieSession.js'][97]++;
    return debug("not secured");
  }
  _$jscoverage['middleware/cookieSession.js'][100]++;
  debug("serializing %j", req.session);
  _$jscoverage['middleware/cookieSession.js'][101]++;
  var val = "j:" + JSON.stringify(req.session);
  _$jscoverage['middleware/cookieSession.js'][104]++;
  if (originalHash == crc16(val)) {
    _$jscoverage['middleware/cookieSession.js'][104]++;
    return debug("unmodified session");
  }
  _$jscoverage['middleware/cookieSession.js'][107]++;
  val = "s:" + signature.sign(val, secret);
  _$jscoverage['middleware/cookieSession.js'][108]++;
  val = cookie.serialize(key, val);
  _$jscoverage['middleware/cookieSession.js'][109]++;
  debug("set-cookie %j", cookie);
  _$jscoverage['middleware/cookieSession.js'][110]++;
  res.setHeader("Set-Cookie", val);
}));
  _$jscoverage['middleware/cookieSession.js'][113]++;
  next();
});
});
_$jscoverage['middleware/cookieSession.js'].source = ["","/*!"," * Connect - cookieSession"," * Copyright(c) 2011 Sencha Inc."," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var utils = require('./../utils')","  , Cookie = require('./session/cookie')","  , debug = require('debug')('connect:cookieSession')","  , signature = require('cookie-signature')","  , crc16 = require('crc').crc16;","","/**"," * Cookie Session:"," *"," *   Cookie session middleware."," *"," *      var app = connect();"," *      app.use(connect.cookieParser());"," *      app.use(connect.cookieSession({ secret: 'tobo!', cookie: { maxAge: 60 * 60 * 1000 }}));"," *"," * Options:"," *"," *   - `key` cookie name defaulting to `connect.sess`"," *   - `secret` prevents cookie tampering"," *   - `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }`"," *   - `proxy` trust the reverse proxy when setting secure cookies (via \"x-forwarded-proto\")"," *"," * Clearing sessions:"," *"," *  To clear the session simply set its value to `null`,"," *  `cookieSession()` will then respond with a 1970 Set-Cookie."," *"," *     req.session = null;"," *"," * @param {Object} options"," * @return {Function}"," * @api public"," */","","module.exports = function cookieSession(options){","  // TODO: utilize Session/Cookie to unify API","  options = options || {};","  var key = options.key || 'connect.sess'","    , trustProxy = options.proxy;","","  return function cookieSession(req, res, next) {","","    // req.secret is for backwards compatibility","    var secret = options.secret || req.secret;","    if (!secret) throw new Error('`secret` option required for cookie sessions');","","    // default session","    req.session = {};","    var cookie = req.session.cookie = new Cookie(options.cookie);","","    // pathname mismatch","    if (0 != req.originalUrl.indexOf(cookie.path)) return next();","","    // cookieParser secret","    if (!options.secret &amp;&amp; req.secret) {","      req.session = req.signedCookies[key] || {};","    } else {","      // TODO: refactor","      var rawCookie = req.cookies[key];","      if (rawCookie) {","        var unsigned = utils.parseSignedCookie(rawCookie, secret);","        if (unsigned) {","          var originalHash = crc16(unsigned);","          req.session = utils.parseJSONCookie(unsigned) || {};","        }","      }","    }","","    res.on('header', function(){","      // removed","      if (!req.session) {","        debug('clear session');","        cookie.expires = new Date(0);","        res.setHeader('Set-Cookie', cookie.serialize(key, ''));","        return;","      }","","      delete req.session.cookie;","","      // check security","      var proto = (req.headers['x-forwarded-proto'] || '').toLowerCase()","        , tls = req.connection.encrypted || (trustProxy &amp;&amp; 'https' == proto)","        , secured = cookie.secure &amp;&amp; tls;","","      // only send secure cookies via https","      if (cookie.secure &amp;&amp; !secured) return debug('not secured');","","      // serialize","      debug('serializing %j', req.session);","      var val = 'j:' + JSON.stringify(req.session);","","      // compare hashes, no need to set-cookie if unchanged","      if (originalHash == crc16(val)) return debug('unmodified session');","","      // set-cookie","      val = 's:' + signature.sign(val, secret);","      val = cookie.serialize(key, val);","      debug('set-cookie %j', cookie);","      res.setHeader('Set-Cookie', val);","    });","","    next();","  };","};"];
