From e8a2753e194070a117d30c1ea0764b01517c5af8 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 12 Dec 2014 17:35:49 -0600 Subject: [PATCH] Don't log HTTP 413, just send it to the client and be done --- lib/nodefilterlist.js | 57 +++++++++++++++++++++++++++++++++++++++++++ lib/web/webserver.js | 7 +++++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 lib/nodefilterlist.js diff --git a/lib/nodefilterlist.js b/lib/nodefilterlist.js new file mode 100644 index 00000000..3eea873a --- /dev/null +++ b/lib/nodefilterlist.js @@ -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; + } + } +}; diff --git a/lib/web/webserver.js b/lib/web/webserver.js index e9ad8744..bc733f23 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -204,7 +204,10 @@ module.exports = { req._ip = ipForRequest(req); 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(morgan(LOG_FORMAT, { stream: require("fs").createWriteStream(path.join(__dirname, "..", "..", @@ -247,6 +250,8 @@ module.exports = { return res.status(400).send("Malformed path: " + req.path); } else if (err.message && err.message.match(/requested range not/i)) { 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)) { return res.status(400).end("Bad Request"); }