From 34e04b7ca602f595ddabc6f07e1f7c28da3885b0 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 19 Jul 2018 21:28:31 +0100 Subject: [PATCH] Minor tweaks for #3362 --- core/modules/server/server.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/modules/server/server.js b/core/modules/server/server.js index 5d67ce899..1c8f9724f 100644 --- a/core/modules/server/server.js +++ b/core/modules/server/server.js @@ -196,12 +196,11 @@ Server.prototype.requestHandler = function(request,response) { response.end(); return; } - - //receive the request body if necessary and hand off to the route handler - if(route.bodyFormat === "stream" || request.method === "GET" || request.method === "HEAD"){ - //let the route handle the request stream itself + // Receive the request body if necessary and hand off to the route handler + if(route.bodyFormat === "stream" || request.method === "GET" || request.method === "HEAD") { + // Let the route handle the request stream itself route.handler(request,response,state); - } else if(route.bodyFormat === "string" || !route.bodyFormat){ + } else if(route.bodyFormat === "string" || !route.bodyFormat) { // Set the encoding for the incoming request request.setEncoding("utf8"); var data = ""; @@ -212,17 +211,18 @@ Server.prototype.requestHandler = function(request,response) { state.data = data; route.handler(request,response,state); }); - } else if(route.bodyFormat === "buffer"){ + } else if(route.bodyFormat === "buffer") { var data = []; request.on("data",function(chunk) { data.push(chunk); }); - request.on("end",function(){ + request.on("end",function() { state.data = Buffer.concat(data); route.handler(request,response,state); }) } else { - throw "Invalid bodyFormat " + route.bodyFormat + " in route " + route.method + " " + route.path.source; + response.writeHead(400,"Invalid bodyFormat " + route.bodyFormat + " in route " + route.method + " " + route.path.source); + response.end(); } };