/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['response.js']) {
  _$jscoverage['response.js'] = [];
  _$jscoverage['response.js'][12] = 0;
  _$jscoverage['response.js'][28] = 0;
  _$jscoverage['response.js'][40] = 0;
  _$jscoverage['response.js'][41] = 0;
  _$jscoverage['response.js'][42] = 0;
  _$jscoverage['response.js'][58] = 0;
  _$jscoverage['response.js'][59] = 0;
  _$jscoverage['response.js'][60] = 0;
  _$jscoverage['response.js'][61] = 0;
  _$jscoverage['response.js'][62] = 0;
  _$jscoverage['response.js'][82] = 0;
  _$jscoverage['response.js'][83] = 0;
  _$jscoverage['response.js'][87] = 0;
  _$jscoverage['response.js'][88] = 0;
  _$jscoverage['response.js'][89] = 0;
  _$jscoverage['response.js'][92] = 0;
  _$jscoverage['response.js'][95] = 0;
  _$jscoverage['response.js'][96] = 0;
  _$jscoverage['response.js'][97] = 0;
  _$jscoverage['response.js'][98] = 0;
  _$jscoverage['response.js'][101] = 0;
  _$jscoverage['response.js'][102] = 0;
  _$jscoverage['response.js'][103] = 0;
  _$jscoverage['response.js'][105] = 0;
  _$jscoverage['response.js'][108] = 0;
  _$jscoverage['response.js'][109] = 0;
  _$jscoverage['response.js'][110] = 0;
  _$jscoverage['response.js'][111] = 0;
  _$jscoverage['response.js'][113] = 0;
  _$jscoverage['response.js'][115] = 0;
  _$jscoverage['response.js'][119] = 0;
  _$jscoverage['response.js'][120] = 0;
  _$jscoverage['response.js'][126] = 0;
  _$jscoverage['response.js'][127] = 0;
  _$jscoverage['response.js'][128] = 0;
  _$jscoverage['response.js'][129] = 0;
  _$jscoverage['response.js'][133] = 0;
  _$jscoverage['response.js'][134] = 0;
  _$jscoverage['response.js'][153] = 0;
  _$jscoverage['response.js'][155] = 0;
  _$jscoverage['response.js'][156] = 0;
  _$jscoverage['response.js'][157] = 0;
  _$jscoverage['response.js'][160] = 0;
  _$jscoverage['response.js'][167] = 0;
  _$jscoverage['response.js'][168] = 0;
  _$jscoverage['response.js'][170] = 0;
  _$jscoverage['response.js'][171] = 0;
  _$jscoverage['response.js'][172] = 0;
  _$jscoverage['response.js'][175] = 0;
  _$jscoverage['response.js'][198] = 0;
  _$jscoverage['response.js'][199] = 0;
  _$jscoverage['response.js'][205] = 0;
  _$jscoverage['response.js'][206] = 0;
  _$jscoverage['response.js'][207] = 0;
  _$jscoverage['response.js'][211] = 0;
  _$jscoverage['response.js'][212] = 0;
  _$jscoverage['response.js'][214] = 0;
  _$jscoverage['response.js'][219] = 0;
  _$jscoverage['response.js'][222] = 0;
  _$jscoverage['response.js'][225] = 0;
  _$jscoverage['response.js'][228] = 0;
  _$jscoverage['response.js'][230] = 0;
  _$jscoverage['response.js'][233] = 0;
  _$jscoverage['response.js'][237] = 0;
  _$jscoverage['response.js'][238] = 0;
  _$jscoverage['response.js'][255] = 0;
  _$jscoverage['response.js'][257] = 0;
  _$jscoverage['response.js'][258] = 0;
  _$jscoverage['response.js'][259] = 0;
  _$jscoverage['response.js'][262] = 0;
  _$jscoverage['response.js'][285] = 0;
  _$jscoverage['response.js'][287] = 0;
  _$jscoverage['response.js'][341] = 0;
  _$jscoverage['response.js'][342] = 0;
  _$jscoverage['response.js'][352] = 0;
  _$jscoverage['response.js'][353] = 0;
  _$jscoverage['response.js'][354] = 0;
  _$jscoverage['response.js'][361] = 0;
  _$jscoverage['response.js'][363] = 0;
  _$jscoverage['response.js'][364] = 0;
  _$jscoverage['response.js'][365] = 0;
  _$jscoverage['response.js'][366] = 0;
  _$jscoverage['response.js'][367] = 0;
  _$jscoverage['response.js'][373] = 0;
  _$jscoverage['response.js'][374] = 0;
  _$jscoverage['response.js'][375] = 0;
  _$jscoverage['response.js'][378] = 0;
  _$jscoverage['response.js'][379] = 0;
  _$jscoverage['response.js'][380] = 0;
  _$jscoverage['response.js'][382] = 0;
  _$jscoverage['response.js'][383] = 0;
  _$jscoverage['response.js'][384] = 0;
  _$jscoverage['response.js'][385] = 0;
  _$jscoverage['response.js'][388] = 0;
  _$jscoverage['response.js'][399] = 0;
  _$jscoverage['response.js'][400] = 0;
  _$jscoverage['response.js'][401] = 0;
  _$jscoverage['response.js'][404] = 0;
  _$jscoverage['response.js'][422] = 0;
  _$jscoverage['response.js'][423] = 0;
  _$jscoverage['response.js'][424] = 0;
  _$jscoverage['response.js'][426] = 0;
  _$jscoverage['response.js'][427] = 0;
  _$jscoverage['response.js'][430] = 0;
  _$jscoverage['response.js'][441] = 0;
  _$jscoverage['response.js'][442] = 0;
  _$jscoverage['response.js'][454] = 0;
  _$jscoverage['response.js'][455] = 0;
  _$jscoverage['response.js'][456] = 0;
  _$jscoverage['response.js'][471] = 0;
  _$jscoverage['response.js'][472] = 0;
  _$jscoverage['response.js'][473] = 0;
  _$jscoverage['response.js'][474] = 0;
  _$jscoverage['response.js'][475] = 0;
  _$jscoverage['response.js'][476] = 0;
  _$jscoverage['response.js'][501] = 0;
  _$jscoverage['response.js'][502] = 0;
  _$jscoverage['response.js'][503] = 0;
  _$jscoverage['response.js'][504] = 0;
  _$jscoverage['response.js'][505] = 0;
  _$jscoverage['response.js'][506] = 0;
  _$jscoverage['response.js'][507] = 0;
  _$jscoverage['response.js'][508] = 0;
  _$jscoverage['response.js'][543] = 0;
  _$jscoverage['response.js'][544] = 0;
  _$jscoverage['response.js'][551] = 0;
  _$jscoverage['response.js'][552] = 0;
  _$jscoverage['response.js'][553] = 0;
  _$jscoverage['response.js'][557] = 0;
  _$jscoverage['response.js'][560] = 0;
  _$jscoverage['response.js'][563] = 0;
  _$jscoverage['response.js'][564] = 0;
  _$jscoverage['response.js'][567] = 0;
  _$jscoverage['response.js'][568] = 0;
  _$jscoverage['response.js'][570] = 0;
  _$jscoverage['response.js'][571] = 0;
  _$jscoverage['response.js'][575] = 0;
  _$jscoverage['response.js'][576] = 0;
  _$jscoverage['response.js'][580] = 0;
  _$jscoverage['response.js'][582] = 0;
  _$jscoverage['response.js'][586] = 0;
  _$jscoverage['response.js'][591] = 0;
  _$jscoverage['response.js'][592] = 0;
  _$jscoverage['response.js'][593] = 0;
  _$jscoverage['response.js'][617] = 0;
  _$jscoverage['response.js'][618] = 0;
  _$jscoverage['response.js'][624] = 0;
  _$jscoverage['response.js'][625] = 0;
  _$jscoverage['response.js'][628] = 0;
  _$jscoverage['response.js'][630] = 0;
  _$jscoverage['response.js'][633] = 0;
  _$jscoverage['response.js'][634] = 0;
  _$jscoverage['response.js'][635] = 0;
  _$jscoverage['response.js'][639] = 0;
  _$jscoverage['response.js'][643] = 0;
  _$jscoverage['response.js'][648] = 0;
  _$jscoverage['response.js'][649] = 0;
  _$jscoverage['response.js'][650] = 0;
  _$jscoverage['response.js'][651] = 0;
  _$jscoverage['response.js'][653] = 0;
  _$jscoverage['response.js'][654] = 0;
  _$jscoverage['response.js'][655] = 0;
  _$jscoverage['response.js'][656] = 0;
  _$jscoverage['response.js'][659] = 0;
  _$jscoverage['response.js'][663] = 0;
}
_$jscoverage['response.js'][12]++;
var fs = require("fs"), http = require("http"), path = require("path"), connect = require("connect"), utils = connect.utils, accept = require("./utils").accept, statusCodes = http.STATUS_CODES, send = connect["static"].send, mime = require("mime"), basename = path.basename, join = path.join;
_$jscoverage['response.js'][28]++;
var res = module.exports = {__proto__: http.ServerResponse.prototype};
_$jscoverage['response.js'][40]++;
res.status = (function (code) {
  _$jscoverage['response.js'][41]++;
  this.statusCode = code;
  _$jscoverage['response.js'][42]++;
  return this;
});
_$jscoverage['response.js'][58]++;
res.cache = (function (type, options) {
  _$jscoverage['response.js'][59]++;
  var val = type;
  _$jscoverage['response.js'][60]++;
  options = options || {};
  _$jscoverage['response.js'][61]++;
  if (options.maxAge) {
    _$jscoverage['response.js'][61]++;
    val += ", max-age=" + (options.maxAge / 1000);
  }
  _$jscoverage['response.js'][62]++;
  return this.set("Cache-Control", val);
});
_$jscoverage['response.js'][82]++;
res.send = (function (body) {
  _$jscoverage['response.js'][83]++;
  var req = this.req, head = "HEAD" == req.method;
  _$jscoverage['response.js'][87]++;
  if (2 == arguments.length) {
    _$jscoverage['response.js'][88]++;
    this.statusCode = body;
    _$jscoverage['response.js'][89]++;
    body = arguments[1];
  }
  _$jscoverage['response.js'][92]++;
  switch (typeof body) {
  case "number":
    _$jscoverage['response.js'][95]++;
    this.get("Content-Type") || this.contentType(".txt");
    _$jscoverage['response.js'][96]++;
    this.statusCode = body;
    _$jscoverage['response.js'][97]++;
    body = http.STATUS_CODES[body];
    _$jscoverage['response.js'][98]++;
    break;
  case "string":
    _$jscoverage['response.js'][101]++;
    if (! this.get("Content-Type")) {
      _$jscoverage['response.js'][102]++;
      this.charset = this.charset || "utf-8";
      _$jscoverage['response.js'][103]++;
      this.contentType(".html");
    }
    _$jscoverage['response.js'][105]++;
    break;
  case "boolean":
  case "object":
    _$jscoverage['response.js'][108]++;
    if (null == body) {
      _$jscoverage['response.js'][109]++;
      body = "";
    }
    else {
      _$jscoverage['response.js'][110]++;
      if (Buffer.isBuffer(body)) {
        _$jscoverage['response.js'][111]++;
        this.get("Content-Type") || this.contentType(".bin");
      }
      else {
        _$jscoverage['response.js'][113]++;
        return this.json(body);
      }
    }
    _$jscoverage['response.js'][115]++;
    break;
  }
  _$jscoverage['response.js'][119]++;
  if (undefined !== body && ! this.get("Content-Length")) {
    _$jscoverage['response.js'][120]++;
    this.set("Content-Length", Buffer.isBuffer(body)? body.length: Buffer.byteLength(body));
  }
  _$jscoverage['response.js'][126]++;
  if (204 == this.statusCode || 304 == this.statusCode) {
    _$jscoverage['response.js'][127]++;
    this.removeHeader("Content-Type");
    _$jscoverage['response.js'][128]++;
    this.removeHeader("Content-Length");
    _$jscoverage['response.js'][129]++;
    body = "";
  }
  _$jscoverage['response.js'][133]++;
  this.end(head? null: body);
  _$jscoverage['response.js'][134]++;
  return this;
});
_$jscoverage['response.js'][153]++;
res.json = (function (obj) {
  _$jscoverage['response.js'][155]++;
  if (2 == arguments.length) {
    _$jscoverage['response.js'][156]++;
    this.statusCode = obj;
    _$jscoverage['response.js'][157]++;
    obj = arguments[1];
  }
  _$jscoverage['response.js'][160]++;
  var settings = this.app.settings, jsonp = settings["jsonp callback"], replacer = settings["json replacer"], spaces = settings["json spaces"], body = JSON.stringify(obj, replacer, spaces), callback = this.req.query.callback;
  _$jscoverage['response.js'][167]++;
  this.charset = this.charset || "utf-8";
  _$jscoverage['response.js'][168]++;
  this.set("Content-Type", "application/json");
  _$jscoverage['response.js'][170]++;
  if (callback && jsonp) {
    _$jscoverage['response.js'][171]++;
    this.set("Content-Type", "text/javascript");
    _$jscoverage['response.js'][172]++;
    body = callback.replace(/[^\w$.]/g, "") + "(" + body + ");";
  }
  _$jscoverage['response.js'][175]++;
  return this.send(body);
});
_$jscoverage['response.js'][198]++;
res.sendfile = (function (path, options, fn) {
  _$jscoverage['response.js'][199]++;
  var self = this, req = self.req, next = this.req.next, options = options || {};
  _$jscoverage['response.js'][205]++;
  if ("function" == typeof options) {
    _$jscoverage['response.js'][206]++;
    fn = options;
    _$jscoverage['response.js'][207]++;
    options = {};
  }
  _$jscoverage['response.js'][211]++;
  options.callback = (function (err) {
  _$jscoverage['response.js'][212]++;
  if (err) {
    _$jscoverage['response.js'][214]++;
    if ("ENOENT" == err.code) {
      _$jscoverage['response.js'][214]++;
      err = 404;
    }
    _$jscoverage['response.js'][219]++;
    if ("number" == typeof err) {
      _$jscoverage['response.js'][219]++;
      err = utils.error(err);
    }
    _$jscoverage['response.js'][222]++;
    if (! self.headerSent) {
      _$jscoverage['response.js'][222]++;
      self.removeHeader("Content-Disposition");
    }
    _$jscoverage['response.js'][225]++;
    if (fn) {
      _$jscoverage['response.js'][225]++;
      return fn(err);
    }
    _$jscoverage['response.js'][228]++;
    if (self.headerSent) {
      _$jscoverage['response.js'][228]++;
      return;
    }
    _$jscoverage['response.js'][230]++;
    return req.next(err);
  }
  _$jscoverage['response.js'][233]++;
  fn && fn();
});
  _$jscoverage['response.js'][237]++;
  options.path = encodeURIComponent(path);
  _$jscoverage['response.js'][238]++;
  send(this.req, this, next, options);
});
_$jscoverage['response.js'][255]++;
res.download = (function (path, filename, fn) {
  _$jscoverage['response.js'][257]++;
  if ("function" == typeof filename) {
    _$jscoverage['response.js'][258]++;
    fn = filename;
    _$jscoverage['response.js'][259]++;
    filename = null;
  }
  _$jscoverage['response.js'][262]++;
  return this.attachment(filename || path).sendfile(path, fn);
});
_$jscoverage['response.js'][285]++;
res.contentType = res.type = (function (type) {
  _$jscoverage['response.js'][287]++;
  return this.set("Content-Type", mime.lookup(type));
});
_$jscoverage['response.js'][341]++;
res.format = (function (obj) {
  _$jscoverage['response.js'][342]++;
  var keys = Object.keys(obj), types = [], req = this.req, next = req.next, accepted = req.accepted, acceptedlen = accepted.length, type, key;
  _$jscoverage['response.js'][352]++;
  if (acceptedlen) {
    _$jscoverage['response.js'][353]++;
    for (var i = 0; i < keys.length; ++i) {
      _$jscoverage['response.js'][354]++;
      types.push(~ keys[i].indexOf("/")? keys[i]: mime.lookup(keys[i]));
}
  }
  _$jscoverage['response.js'][361]++;
out:
  for (var i = 0; i < acceptedlen; ++i) {
    _$jscoverage['response.js'][363]++;
    for (var j = 0, jlen = types.length; j < jlen; ++j) {
      _$jscoverage['response.js'][364]++;
      if (accept(types[j].split("/"), accepted[i])) {
        _$jscoverage['response.js'][365]++;
        key = keys[j];
        _$jscoverage['response.js'][366]++;
        type = types[j];
        _$jscoverage['response.js'][367]++;
        break out;
      }
}
}
  _$jscoverage['response.js'][373]++;
  if (! acceptedlen) {
    _$jscoverage['response.js'][374]++;
    key = keys[0];
    _$jscoverage['response.js'][375]++;
    type = types[0];
  }
  _$jscoverage['response.js'][378]++;
  if (key) {
    _$jscoverage['response.js'][379]++;
    this.set("Content-Type", type);
    _$jscoverage['response.js'][380]++;
    obj[key](req, this, next);
  }
  else {
    _$jscoverage['response.js'][382]++;
    var err = new Error("Not Acceptable");
    _$jscoverage['response.js'][383]++;
    err.status = 406;
    _$jscoverage['response.js'][384]++;
    err.types = types;
    _$jscoverage['response.js'][385]++;
    next(err);
  }
  _$jscoverage['response.js'][388]++;
  return this;
});
_$jscoverage['response.js'][399]++;
res.attachment = (function (filename) {
  _$jscoverage['response.js'][400]++;
  if (filename) {
    _$jscoverage['response.js'][400]++;
    this.type(filename);
  }
  _$jscoverage['response.js'][401]++;
  this.set("Content-Disposition", filename? "attachment; filename=\"" + basename(filename) + "\"": "attachment");
  _$jscoverage['response.js'][404]++;
  return this;
});
_$jscoverage['response.js'][422]++;
res.set = (function (field, val) {
  _$jscoverage['response.js'][423]++;
  if (2 == arguments.length) {
    _$jscoverage['response.js'][424]++;
    this.setHeader(field, val);
  }
  else {
    _$jscoverage['response.js'][426]++;
    for (var key in field) {
      _$jscoverage['response.js'][427]++;
      this.setHeader(key, field[key]);
}
  }
  _$jscoverage['response.js'][430]++;
  return this;
});
_$jscoverage['response.js'][441]++;
res.get = (function (field) {
  _$jscoverage['response.js'][442]++;
  return this.getHeader(field);
});
_$jscoverage['response.js'][454]++;
res.clearCookie = (function (name, options) {
  _$jscoverage['response.js'][455]++;
  var opts = {expires: new Date(1), path: "/"};
  _$jscoverage['response.js'][456]++;
  return this.cookie(name, "", options? utils.merge(opts, options): opts);
});
_$jscoverage['response.js'][471]++;
res.signedCookie = (function (name, val, options) {
  _$jscoverage['response.js'][472]++;
  var secret = this.req.secret;
  _$jscoverage['response.js'][473]++;
  if (! secret) {
    _$jscoverage['response.js'][473]++;
    throw new Error("connect.cookieParser(\"secret\") required for signed cookies");
  }
  _$jscoverage['response.js'][474]++;
  if ("object" == typeof val) {
    _$jscoverage['response.js'][474]++;
    val = "j:" + JSON.stringify(val);
  }
  _$jscoverage['response.js'][475]++;
  val = utils.sign(val, secret);
  _$jscoverage['response.js'][476]++;
  return this.cookie(name, val, options);
});
_$jscoverage['response.js'][501]++;
res.cookie = (function (name, val, options) {
  _$jscoverage['response.js'][502]++;
  options = options || {};
  _$jscoverage['response.js'][503]++;
  if ("object" == typeof val) {
    _$jscoverage['response.js'][503]++;
    val = "j:" + JSON.stringify(val);
  }
  _$jscoverage['response.js'][504]++;
  if ("maxAge" in options) {
    _$jscoverage['response.js'][504]++;
    options.expires = new Date(Date.now() + options.maxAge);
  }
  _$jscoverage['response.js'][505]++;
  if (null == options.path) {
    _$jscoverage['response.js'][505]++;
    options.path = "/";
  }
  _$jscoverage['response.js'][506]++;
  var cookie = utils.serializeCookie(name, val, options);
  _$jscoverage['response.js'][507]++;
  this.set("Set-Cookie", cookie);
  _$jscoverage['response.js'][508]++;
  return this;
});
_$jscoverage['response.js'][543]++;
res.redirect = (function (url) {
  _$jscoverage['response.js'][544]++;
  var app = this.app, req = this.req, head = "HEAD" == req.method, status = 302, body;
  _$jscoverage['response.js'][551]++;
  if (2 == arguments.length) {
    _$jscoverage['response.js'][552]++;
    status = url;
    _$jscoverage['response.js'][553]++;
    url = arguments[1];
  }
  _$jscoverage['response.js'][557]++;
  var map = {back: req.get("Referrer") || "/"};
  _$jscoverage['response.js'][560]++;
  url = map[url] || url;
  _$jscoverage['response.js'][563]++;
  if (! ~ url.indexOf("://")) {
    _$jscoverage['response.js'][564]++;
    var path = app.path();
    _$jscoverage['response.js'][567]++;
    if (0 == url.indexOf("./") || 0 == url.indexOf("..")) {
      _$jscoverage['response.js'][568]++;
      url = req.path + "/" + url;
    }
    else {
      _$jscoverage['response.js'][570]++;
      if ("/" != url[0]) {
        _$jscoverage['response.js'][571]++;
        url = path + "/" + url;
      }
    }
    _$jscoverage['response.js'][575]++;
    var host = req.get("Host");
    _$jscoverage['response.js'][576]++;
    url = req.protocol + "://" + host + url;
  }
  _$jscoverage['response.js'][580]++;
  this.format({"text/plain": (function () {
  _$jscoverage['response.js'][582]++;
  body = statusCodes[status] + ". Redirecting to " + url;
}), "text/html": (function () {
  _$jscoverage['response.js'][586]++;
  body = "<p>" + statusCodes[status] + ". Redirecting to <a href=\"" + url + "\">" + url + "</a></p>";
})});
  _$jscoverage['response.js'][591]++;
  this.statusCode = status;
  _$jscoverage['response.js'][592]++;
  this.set("Location", url);
  _$jscoverage['response.js'][593]++;
  this.end(head? null: body);
});
_$jscoverage['response.js'][617]++;
res.render = (function (view, options, fn) {
  _$jscoverage['response.js'][618]++;
  var self = this, options = options || {}, req = this.req, app = req.app;
  _$jscoverage['response.js'][624]++;
  if ("function" == typeof options) {
    _$jscoverage['response.js'][625]++;
    fn = options, options = {};
  }
  _$jscoverage['response.js'][628]++;
  function render() {
    _$jscoverage['response.js'][630]++;
    options.locals = self.locals;
    _$jscoverage['response.js'][633]++;
    fn = fn || (function (err, str) {
  _$jscoverage['response.js'][634]++;
  if (err) {
    _$jscoverage['response.js'][634]++;
    return req.next(err);
  }
  _$jscoverage['response.js'][635]++;
  self.send(str);
});
    _$jscoverage['response.js'][639]++;
    app.render(view, options, fn);
}
  _$jscoverage['response.js'][643]++;
  var callbacks = app.viewCallbacks, pending = callbacks.length, len = pending, done;
  _$jscoverage['response.js'][648]++;
  if (len) {
    _$jscoverage['response.js'][649]++;
    for (var i = 0; i < len; ++i) {
      _$jscoverage['response.js'][650]++;
      callbacks[i](req, self, (function (err) {
  _$jscoverage['response.js'][651]++;
  if (done) {
    _$jscoverage['response.js'][651]++;
    return;
  }
  _$jscoverage['response.js'][653]++;
  if (err) {
    _$jscoverage['response.js'][654]++;
    req.next(err);
    _$jscoverage['response.js'][655]++;
    done = true;
    _$jscoverage['response.js'][656]++;
    return;
  }
  _$jscoverage['response.js'][659]++;
  --pending || render();
}));
}
  }
  else {
    _$jscoverage['response.js'][663]++;
    render();
  }
});
_$jscoverage['response.js'].source = ["","/*!"," * Express - response"," * Copyright(c) 2010 TJ Holowaychuk &lt;tj@vision-media.ca&gt;"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var fs = require('fs')","  , http = require('http')","  , path = require('path')","  , connect = require('connect')","  , utils = connect.utils","  , accept = require('./utils').accept","  , statusCodes = http.STATUS_CODES","  , send = connect.static.send","  , mime = require('mime')","  , basename = path.basename","  , join = path.join;","","/**"," * Response prototype."," */","","var res = module.exports = {","  __proto__: http.ServerResponse.prototype","};","","/**"," * Set status `code`."," *"," * @param {Number} code"," * @return {ServerResponse}"," * @api public"," */","","res.status = function(code){","  this.statusCode = code;","  return this;","};","","/**"," * Set Cache-Control to the given `type` and `options`."," *"," * Options:"," *"," *  - `maxAge` in milliseconds"," *"," * @param {String} type"," * @param {Object} options"," * @return {ServerResponse}"," * @api public"," */","","res.cache = function(type, options){","  var val = type;","  options = options || {};","  if (options.maxAge) val += ', max-age=' + (options.maxAge / 1000); ","  return this.set('Cache-Control', val);","};","","/**"," * Send a response."," *"," * Examples:"," *"," *     res.send(new Buffer('wahoo'));"," *     res.send({ some: 'json' });"," *     res.send('&lt;p&gt;some html&lt;/p&gt;');"," *     res.send(404, 'Sorry, cant find that');"," *     res.send(404);"," *"," * @param {Mixed} body or status"," * @param {Mixed} body"," * @return {ServerResponse}"," * @api public"," */","","res.send = function(body){","  var req = this.req","    , head = 'HEAD' == req.method;","","  // allow status / body","  if (2 == arguments.length) {","    this.statusCode = body;","    body = arguments[1];","  }","","  switch (typeof body) {","    // response status","    case 'number':","      this.get('Content-Type') || this.contentType('.txt');","      this.statusCode = body;","      body = http.STATUS_CODES[body];","      break;","    // string defaulting to html","    case 'string':","      if (!this.get('Content-Type')) {","        this.charset = this.charset || 'utf-8';","        this.contentType('.html');","      }","      break;","    case 'boolean':","    case 'object':","      if (null == body) {","        body = '';","      } else if (Buffer.isBuffer(body)) {","        this.get('Content-Type') || this.contentType('.bin');","      } else {","        return this.json(body);","      }","      break;","  }","","  // populate Content-Length","  if (undefined !== body &amp;&amp; !this.get('Content-Length')) {","    this.set('Content-Length', Buffer.isBuffer(body)","      ? body.length","      : Buffer.byteLength(body));","  }","","  // strip irrelevant headers","  if (204 == this.statusCode || 304 == this.statusCode) {","    this.removeHeader('Content-Type');","    this.removeHeader('Content-Length');","    body = '';","  }","","  // respond","  this.end(head ? null : body);","  return this;","};","","/**"," * Send JSON response."," *"," * Examples:"," *"," *     res.json(null);"," *     res.json({ user: 'tj' });"," *     res.json(500, 'oh noes!');"," *     res.json(404, 'I dont have that');"," *"," * @param {Mixed} obj or status"," * @param {Mixed} obj"," * @return {ServerResponse}"," * @api public"," */","","res.json = function(obj){","  // allow status / body","  if (2 == arguments.length) {","    this.statusCode = obj;","    obj = arguments[1];","  }","","  var settings = this.app.settings","    , jsonp = settings['jsonp callback']","    , replacer = settings['json replacer']","    , spaces = settings['json spaces']","    , body = JSON.stringify(obj, replacer, spaces)","    , callback = this.req.query.callback;","","  this.charset = this.charset || 'utf-8';","  this.set('Content-Type', 'application/json');","","  if (callback &amp;&amp; jsonp) {","    this.set('Content-Type', 'text/javascript');","    body = callback.replace(/[^\\w$.]/g, '') + '(' + body + ');';","  }","","  return this.send(body);","};","","/**"," * Transfer the file at the given `path`."," * "," * Automatically sets the _Content-Type_ response header field."," * The callback `fn(err)` is invoked when the transfer is complete"," * or when an error occurs. Be sure to check `res.sentHeader`"," * if you wish to attempt responding, as the header and some data"," * may have already been transferred."," *"," * Options:"," *"," *   - `maxAge` defaulting to 0"," *   - `root`   root directory for relative filenames"," *"," * @param {String} path"," * @param {Object|Function} options or fn"," * @param {Function} fn"," * @api public"," */","","res.sendfile = function(path, options, fn){","  var self = this","    , req = self.req","    , next = this.req.next","    , options = options || {};","","  // support function as second arg","  if ('function' == typeof options) {","    fn = options;","    options = {};","  }","","  // callback","  options.callback = function(err){","    if (err) {","      // cast ENOENT","      if ('ENOENT' == err.code) err = 404;","","      // coerce numeric error to an Error","      // TODO: remove","      // TODO: remove docs for headerSent?","      if ('number' == typeof err) err = utils.error(err);","","      // ditch content-disposition to prevent funky responses","      if (!self.headerSent) self.removeHeader('Content-Disposition');","","      // woot! callback available","      if (fn) return fn(err);","","      // lost in limbo if there's no callback","      if (self.headerSent) return;","","      return req.next(err);","    }","","    fn &amp;&amp; fn();","  };","","  // transfer","  options.path = encodeURIComponent(path);","  send(this.req, this, next, options);","};","","/**"," * Transfer the file at the given `path` as an attachment."," *"," * Optionally providing an alternate attachment `filename`,"," * and optional callback `fn(err)`. The callback is invoked"," * when the data transfer is complete, or when an error has"," * ocurred. Be sure to check `res.headerSent` if you plan to respond."," *"," * @param {String} path"," * @param {String|Function} filename or fn"," * @param {Function} fn"," * @api public"," */","","res.download = function(path, filename, fn){","  // support function as second arg","  if ('function' == typeof filename) {","    fn = filename;","    filename = null;","  }","","  return this.attachment(filename || path).sendfile(path, fn);","};","","/**"," * Set _Content-Type_ response header passed through `mime.lookup()`."," *"," * Examples:"," *"," *     var filename = 'path/to/image.png';"," *     res.contentType(filename);"," *     // res.headers['Content-Type'] is now \"image/png\""," *"," *     res.contentType('.html');"," *     res.contentType('html');"," *     res.contentType('json');"," *     res.contentType('png');"," *     res.type('png');"," *"," * @param {String} type"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.contentType =","res.type = function(type){","  return this.set('Content-Type', mime.lookup(type));","};","","/**"," * Respond to the Acceptable formats using an `obj`"," * of mime-type callbacks."," *"," * This method uses `req.accepted`, an array of"," * acceptable types ordered by their quality values."," * When \"Accept\" is not present the _first_ callback"," * is invoked, otherwise the first match is used. When"," * no match is performed the server responds with"," * 406 \"Not Acceptable\"."," *"," * Content-Type is set for you, however if you choose"," * you may alter this within the callback using `res.type()`"," * or `res.set('Content-Type', ...)`."," *"," *    res.format({"," *      'text/plain': function(){"," *        res.send('hey');"," *      },"," *    "," *      'text/html': function(){"," *        res.send('&lt;p&gt;hey&lt;/p&gt;');"," *      },"," *    "," *      'appliation/json': function(){"," *        res.send({ message: 'hey' });"," *      }"," *    });"," *"," * In addition to canonicalized MIME types you may"," * also use extnames mapped to these types:"," *"," *    res.format({"," *      text: function(){"," *        res.send('hey');"," *      },"," *    "," *      html: function(){"," *        res.send('&lt;p&gt;hey&lt;/p&gt;');"," *      },"," *    "," *      json: function(){"," *        res.send({ message: 'hey' });"," *      }"," *    });"," *"," * @param {Object} obj"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.format = function(obj){","  var keys = Object.keys(obj)","    , types = []","    , req = this.req","    , next = req.next","    , accepted = req.accepted","    , acceptedlen = accepted.length","    , type","    , key;","","  // normalize extnames -&gt; mime","  if (acceptedlen) {","    for (var i = 0; i &lt; keys.length; ++i) {","      types.push(~keys[i].indexOf('/')","        ? keys[i]","        : mime.lookup(keys[i]));","    }","  }","","  // determine most acceptable format","  out:","  for (var i = 0; i &lt; acceptedlen; ++i) {","    for (var j = 0, jlen = types.length; j &lt; jlen; ++j) {","      if (accept(types[j].split('/'), accepted[i])) {","        key = keys[j];","        type = types[j];","        break out;","      }","    }","  }","","  // default to the first","  if (!acceptedlen) {","    key = keys[0];","    type = types[0];","  }","","  if (key) {","    this.set('Content-Type', type);","    obj[key](req, this, next);","  } else {","    var err = new Error('Not Acceptable');","    err.status = 406;","    err.types = types;","    next(err);","  }","","  return this;","};","","/**"," * Set _Content-Disposition_ header to _attachment_ with optional `filename`."," *"," * @param {String} filename"," * @return {ServerResponse}"," * @api public"," */","","res.attachment = function(filename){","  if (filename) this.type(filename);","  this.set('Content-Disposition', filename","    ? 'attachment; filename=\"' + basename(filename) + '\"'","    : 'attachment');","  return this;","};","","/**"," * Set header `field` to `val`, or pass"," * an object of of header fields."," *"," * Examples:"," *"," *    res.set('Accept', 'application/json');"," *    res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });"," *"," * @param {String|Object} field"," * @param {String} val"," * @return {ServerResponse} for chaining"," * @api public"," */","","res.set = function(field, val){","  if (2 == arguments.length) {","    this.setHeader(field, val);","  } else {","    for (var key in field) {","      this.setHeader(key, field[key]);","    }","  }","  return this;","};","","/**"," * Get value for header `field`."," *"," * @param {String} field"," * @return {String}"," * @api public"," */","","res.get = function(field){","  return this.getHeader(field);","};","","/**"," * Clear cookie `name`."," *"," * @param {String} name"," * @param {Object} options"," * @param {ServerResponse} for chaining"," * @api public"," */","","res.clearCookie = function(name, options){","  var opts = { expires: new Date(1), path: '/' };","  return this.cookie(name, '', options","    ? utils.merge(opts, options)","    : opts);","};","","/**"," * Set a signed cookie with the given `name` and `val`."," * See `res.cookie()` for details."," *"," * @param {String} name"," * @param {String|Object} val"," * @param {Object} options"," * @api public"," */","","res.signedCookie = function(name, val, options){","  var secret = this.req.secret;","  if (!secret) throw new Error('connect.cookieParser(\"secret\") required for signed cookies');","  if ('object' == typeof val) val = 'j:' + JSON.stringify(val);","  val = utils.sign(val, secret);","  return this.cookie(name, val, options);","};","","/**"," * Set cookie `name` to `val`, with the given `options`."," *"," * Options:"," *"," *    - `maxAge`   max-age in milliseconds, converted to `expires`"," *    - `path`     defaults to \"/\""," *"," * Examples:"," *"," *    // \"Remember Me\" for 15 minutes"," *    res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });"," *"," *    // save as above"," *    res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })"," *"," * @param {String} name"," * @param {String|Object} val"," * @param {Options} options"," * @api public"," */","","res.cookie = function(name, val, options){","  options = options || {};","  if ('object' == typeof val) val = 'j:' + JSON.stringify(val);","  if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);","  if (null == options.path) options.path = '/';","  var cookie = utils.serializeCookie(name, val, options);","  this.set('Set-Cookie', cookie);","  return this;","};","","/**"," * Redirect to the given `url` with optional response `status`"," * defaulting to 302."," *"," * The given `url` can also be the name of a mapped url, for"," * example by default express supports \"back\" which redirects"," * to the _Referrer_ or _Referer_ headers or \"/\"."," *"," * Examples:"," *"," *    res.redirect('/foo/bar');"," *    res.redirect('http://example.com');"," *    res.redirect(301, 'http://example.com');"," *"," * Mounting:"," *"," *   When an application is mounted, and `res.redirect()`"," *   is given a path that does _not_ lead with \"/\". For "," *   example suppose a \"blog\" app is mounted at \"/blog\","," *   the following redirect would result in \"/blog/login\":"," *"," *      res.redirect('login');"," *"," *   While the leading slash would result in a redirect to \"/login\":"," *"," *      res.redirect('/login');"," *"," * @param {String} url"," * @param {Number} code"," * @api public"," */","","res.redirect = function(url){","  var app = this.app","    , req = this.req","    , head = 'HEAD' == req.method","    , status = 302","    , body;","","  // allow status / url","  if (2 == arguments.length) {","    status = url;","    url = arguments[1];","  }","","  // setup redirect map","  var map = { back: req.get('Referrer') || '/' };","","  // perform redirect","  url = map[url] || url;","","  // relative","  if (!~url.indexOf('://')) {","    var path = app.path();","","    // relative to path","    if (0 == url.indexOf('./') || 0 == url.indexOf('..')) {","      url = req.path + '/' + url;","    // relative to mount-point","    } else if ('/' != url[0]) {","      url = path + '/' + url;","    }","","    // Absolute","    var host = req.get('Host');","    url = req.protocol + '://' + host + url;","  }","","  // Support text/{plain,html} by default","  this.format({","    'text/plain': function(){","      body = statusCodes[status] + '. Redirecting to ' + url;","    },","","    'text/html': function(){","      body = '&lt;p&gt;' + statusCodes[status] + '. Redirecting to &lt;a href=\"' + url + '\"&gt;' + url + '&lt;/a&gt;&lt;/p&gt;';","    }","  })","","  // Respond","  this.statusCode = status;","  this.set('Location', url);","  this.end(head ? null : body);","};","","/**"," * Render `view` with the given `options` and optional callback `fn`."," * When a callback function is given a response will _not_ be made"," * automatically, otherwise a response of _200_ and _text/html_ is given."," *"," * Options:"," *  "," *  - `status`    Response status code (`res.statusCode`)"," *  - `charset`   Set the charset (`res.charset`)"," *"," * Reserved locals:"," *"," *  - `cache`     boolean hinting to the engine it should cache"," *  - `filename`  filename of the view being rendered"," *"," * @param  {String} view"," * @param  {Object|Function} options or callback function"," * @param  {Function} fn"," * @api public"," */","","res.render = function(view, options, fn){","  var self = this","    , options = options || {}","    , req = this.req","    , app = req.app;","","  // support callback function as second arg","  if ('function' == typeof options) {","    fn = options, options = {};","  }","","  function render() {","    // merge res.locals","    options.locals = self.locals;","","    // default callback to respond","    fn = fn || function(err, str){","      if (err) return req.next(err);","      self.send(str);","    };","","    // render","    app.render(view, options, fn);","  }","","  // invoke view callbacks","  var callbacks = app.viewCallbacks","    , pending = callbacks.length","    , len = pending","    , done;","","  if (len) {","    for (var i = 0; i &lt; len; ++i) {","      callbacks[i](req, self, function(err){","        if (done) return;","","        if (err) {","          req.next(err);","          done = true;","          return;","        }","","        --pending || render();","      });","    }","  } else {","    render();","  }","};"];
