1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Minor tweaks for #3362

This commit is contained in:
Jermolene 2018-07-19 21:28:31 +01:00
parent aa8b2e11bb
commit 34e04b7ca6

View File

@ -196,12 +196,11 @@ Server.prototype.requestHandler = function(request,response) {
response.end(); response.end();
return; return;
} }
// Receive the request body if necessary and hand off to the route handler
//receive the request body if necessary and hand off to the route handler if(route.bodyFormat === "stream" || request.method === "GET" || request.method === "HEAD") {
if(route.bodyFormat === "stream" || request.method === "GET" || request.method === "HEAD"){ // Let the route handle the request stream itself
//let the route handle the request stream itself
route.handler(request,response,state); 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 // Set the encoding for the incoming request
request.setEncoding("utf8"); request.setEncoding("utf8");
var data = ""; var data = "";
@ -212,17 +211,18 @@ Server.prototype.requestHandler = function(request,response) {
state.data = data; state.data = data;
route.handler(request,response,state); route.handler(request,response,state);
}); });
} else if(route.bodyFormat === "buffer"){ } else if(route.bodyFormat === "buffer") {
var data = []; var data = [];
request.on("data",function(chunk) { request.on("data",function(chunk) {
data.push(chunk); data.push(chunk);
}); });
request.on("end",function(){ request.on("end",function() {
state.data = Buffer.concat(data); state.data = Buffer.concat(data);
route.handler(request,response,state); route.handler(request,response,state);
}) })
} else { } 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();
} }
}; };