From ecbd65f6310ced234ec1f5e192c239220a7dc136 Mon Sep 17 00:00:00 2001 From: nosthertus Date: Sat, 21 Oct 2017 01:58:24 -0500 Subject: [PATCH] * Content-type request parse fix *Fixed a bug that was causing the body parser to fail on content-type value with parameters --- controllers/protocols/http/signal.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/controllers/protocols/http/signal.js b/controllers/protocols/http/signal.js index 40fe2a2..8310ed1 100644 --- a/controllers/protocols/http/signal.js +++ b/controllers/protocols/http/signal.js @@ -195,10 +195,13 @@ if(multipart === -1){ signal.multipart = false; request.on('data', function(data){ signal.body += data; }); - request.on('end', function(){ - if(request.headers['content-type'].toString().indexOf('application/x-www-form-urlencoded') != -1){ + request.on('end', function(){ + let type = request.headers['content-type'] + .split(";")[0].trim(); // Exclude parameters such as charset=utf-8 + + if(type.toString().indexOf('application/x-www-form-urlencoded') != -1){ signal.body = signal.qs.parse(decodeURIComponent(signal.body)); - } else if(request.headers['content-type'] == "application/json") { + } else if(type == "application/json") { try { signal.body = JSON.parse(signal.body); } catch (error) { /*...*/ }