/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['middleware/json.js']) {
  _$jscoverage['middleware/json.js'] = [];
  _$jscoverage['middleware/json.js'][13] = 0;
  _$jscoverage['middleware/json.js'][20] = 0;
  _$jscoverage['middleware/json.js'][21] = 0;
  _$jscoverage['middleware/json.js'][41] = 0;
  _$jscoverage['middleware/json.js'][42] = 0;
  _$jscoverage['middleware/json.js'][45] = 0;
  _$jscoverage['middleware/json.js'][49] = 0;
  _$jscoverage['middleware/json.js'][50] = 0;
  _$jscoverage['middleware/json.js'][51] = 0;
  _$jscoverage['middleware/json.js'][53] = 0;
  _$jscoverage['middleware/json.js'][56] = 0;
  _$jscoverage['middleware/json.js'][59] = 0;
  _$jscoverage['middleware/json.js'][62] = 0;
  _$jscoverage['middleware/json.js'][63] = 0;
  _$jscoverage['middleware/json.js'][64] = 0;
  _$jscoverage['middleware/json.js'][65] = 0;
  _$jscoverage['middleware/json.js'][66] = 0;
  _$jscoverage['middleware/json.js'][67] = 0;
  _$jscoverage['middleware/json.js'][68] = 0;
  _$jscoverage['middleware/json.js'][70] = 0;
  _$jscoverage['middleware/json.js'][71] = 0;
  _$jscoverage['middleware/json.js'][74] = 0;
  _$jscoverage['middleware/json.js'][75] = 0;
  _$jscoverage['middleware/json.js'][76] = 0;
  _$jscoverage['middleware/json.js'][77] = 0;
  _$jscoverage['middleware/json.js'][79] = 0;
  _$jscoverage['middleware/json.js'][80] = 0;
  _$jscoverage['middleware/json.js'][81] = 0;
}
_$jscoverage['middleware/json.js'][13]++;
var utils = require("../utils"), _limit = require("./limit");
_$jscoverage['middleware/json.js'][20]++;
function noop(req, res, next) {
  _$jscoverage['middleware/json.js'][21]++;
  next();
}
_$jscoverage['middleware/json.js'][41]++;
exports = module.exports = (function (options) {
  _$jscoverage['middleware/json.js'][42]++;
  var options = options || {}, strict = options.strict !== false;
  _$jscoverage['middleware/json.js'][45]++;
  var limit = options.limit? _limit(options.limit): noop;
  _$jscoverage['middleware/json.js'][49]++;
  return (function json(req, res, next) {
  _$jscoverage['middleware/json.js'][50]++;
  if (req._body) {
    _$jscoverage['middleware/json.js'][50]++;
    return next();
  }
  _$jscoverage['middleware/json.js'][51]++;
  req.body = req.body || {};
  _$jscoverage['middleware/json.js'][53]++;
  if (! utils.hasBody(req)) {
    _$jscoverage['middleware/json.js'][53]++;
    return next();
  }
  _$jscoverage['middleware/json.js'][56]++;
  if ("application/json" != utils.mime(req)) {
    _$jscoverage['middleware/json.js'][56]++;
    return next();
  }
  _$jscoverage['middleware/json.js'][59]++;
  req._body = true;
  _$jscoverage['middleware/json.js'][62]++;
  limit(req, res, (function (err) {
  _$jscoverage['middleware/json.js'][63]++;
  if (err) {
    _$jscoverage['middleware/json.js'][63]++;
    return next(err);
  }
  _$jscoverage['middleware/json.js'][64]++;
  var buf = "";
  _$jscoverage['middleware/json.js'][65]++;
  req.setEncoding("utf8");
  _$jscoverage['middleware/json.js'][66]++;
  req.on("data", (function (chunk) {
  _$jscoverage['middleware/json.js'][66]++;
  buf += chunk;
}));
  _$jscoverage['middleware/json.js'][67]++;
  req.on("end", (function () {
  _$jscoverage['middleware/json.js'][68]++;
  var first = buf.trim()[0];
  _$jscoverage['middleware/json.js'][70]++;
  if (0 == buf.length) {
    _$jscoverage['middleware/json.js'][71]++;
    return next(utils.error(400, "invalid json, empty body"));
  }
  _$jscoverage['middleware/json.js'][74]++;
  if (strict && "{" != first && "[" != first) {
    _$jscoverage['middleware/json.js'][74]++;
    return next(utils.error(400, "invalid json"));
  }
  _$jscoverage['middleware/json.js'][75]++;
  try {
    _$jscoverage['middleware/json.js'][76]++;
    req.body = JSON.parse(buf, options.reviver);
    _$jscoverage['middleware/json.js'][77]++;
    next();
  }
  catch (err) {
    _$jscoverage['middleware/json.js'][79]++;
    err.body = buf;
    _$jscoverage['middleware/json.js'][80]++;
    err.status = 400;
    _$jscoverage['middleware/json.js'][81]++;
    next(err);
  }
}));
}));
});
});
_$jscoverage['middleware/json.js'].source = ["","/*!"," * Connect - json"," * Copyright(c) 2010 Sencha Inc."," * Copyright(c) 2011 TJ Holowaychuk"," * MIT Licensed"," */","","/**"," * Module dependencies."," */","","var utils = require('../utils')","  , _limit = require('./limit');","","/**"," * noop middleware."," */","","function noop(req, res, next) {","  next();","}","","/**"," * JSON:"," *"," * Parse JSON request bodies, providing the"," * parsed object as `req.body`."," *"," * Options:"," *"," *   - `strict`  when `false` anything `JSON.parse()` accepts will be parsed"," *   - `reviver`  used as the second \"reviver\" argument for JSON.parse"," *   - `limit`  byte limit disabled by default"," *"," * @param {Object} options"," * @return {Function}"," * @api public"," */","","exports = module.exports = function(options){","  var options = options || {}","    , strict = options.strict !== false;","","  var limit = options.limit","    ? _limit(options.limit)","    : noop;","","  return function json(req, res, next) {","    if (req._body) return next();","    req.body = req.body || {};","","    if (!utils.hasBody(req)) return next();","","    // check Content-Type","    if ('application/json' != utils.mime(req)) return next();","","    // flag as parsed","    req._body = true;","","    // parse","    limit(req, res, function(err){","      if (err) return next(err);","      var buf = '';","      req.setEncoding('utf8');","      req.on('data', function(chunk){ buf += chunk });","      req.on('end', function(){","        var first = buf.trim()[0];","","        if (0 == buf.length) {","          return next(utils.error(400, 'invalid json, empty body'));","        }","        ","        if (strict &amp;&amp; '{' != first &amp;&amp; '[' != first) return next(utils.error(400, 'invalid json'));","        try {","          req.body = JSON.parse(buf, options.reviver);","          next();","        } catch (err){","          err.body = buf;","          err.status = 400;","          next(err);","        }","      });","    });","  }","};"];
