Don't log HTTP 413, just send it to the client and be done

This commit is contained in:
calzoneman 2014-12-12 17:35:49 -06:00
parent a3a9fa074e
commit e8a2753e19
2 changed files with 63 additions and 1 deletions

57
lib/nodefilterlist.js Normal file
View File

@ -0,0 +1,57 @@
function fixFilter(f) {
if (typeof f.name !== "string" ||
typeof f.source !== "string" ||
typeof f.replace !== "string") {
return null;
}
f.replace = f.replace.replace(/([^\\]\\(\d)/g, "$1$$$2");
if (typeof f.flags !== "string") {
f.flags = "";
}
f.active = !!f.active;
f.filterlinks = !!f.filterlinks;
return f;
}
function NodeFilterList(filters) {
if (!filters) filters = [];
this.filters = filters.map(function (f) {
f.regexp = new RegExp(f.source, f.flags);
return f;
});
}
NodeFilterList.prototype.pack = function () {
return this.filters.map(function (f) {
return {
name: f.name,
source: f.source,
flags: f.flags,
replace: f.replace,
active: f.active,
filterlinks: f.filterlinks
};
});
};
NodeFilterList.prototype.addFilter = function (f) {
this.filters.push(f);
};
NodeFilterList.prototype.updateFilter = function (f) {
if (!f.name) return;
for (var i = 0; i < this.filters.length; i++) {
if (this.filters[i].name === filter.name) {
for (var key in f) {
this.filters[i][key] = f[key];
}
break;
}
}
};

View File

@ -204,7 +204,10 @@ module.exports = {
req._ip = ipForRequest(req); req._ip = ipForRequest(req);
next(); next();
}); });
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({
extended: false,
limit: '1kb' // No POST data should ever exceed this size under normal usage
}));
app.use(cookieParser()); app.use(cookieParser());
app.use(morgan(LOG_FORMAT, { app.use(morgan(LOG_FORMAT, {
stream: require("fs").createWriteStream(path.join(__dirname, "..", "..", stream: require("fs").createWriteStream(path.join(__dirname, "..", "..",
@ -247,6 +250,8 @@ module.exports = {
return res.status(400).send("Malformed path: " + req.path); return res.status(400).send("Malformed path: " + req.path);
} else if (err.message && err.message.match(/requested range not/i)) { } else if (err.message && err.message.match(/requested range not/i)) {
return res.status(416).end(); return res.status(416).end();
} else if (err.message && err.message.match(/request entity too large/i)) {
return res.status(413).end();
} else if (err.message && err.message.match(/bad request/i)) { } else if (err.message && err.message.match(/bad request/i)) {
return res.status(400).end("Bad Request"); return res.status(400).end("Bad Request");
} }