From 48d4c73ca3d78331f1d01724c6781aebafdae845 Mon Sep 17 00:00:00 2001 From: Alex Rennie-Lis Date: Sun, 7 Apr 2024 19:02:03 +0100 Subject: [PATCH] Resolved issue 7 --- code/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/code/index.js b/code/index.js index 8c2cc17..a683124 100644 --- a/code/index.js +++ b/code/index.js @@ -97,14 +97,15 @@ listeners.accounting.socket.bind (config.ports.radius_accounting); // HTTP listener const respond = (res, content, status) => { - if (typeof (content) == "string") { - res.write (content); + var type = "text/plain"; + if (typeof (content) != "string") { + content = JSON.stringify (content); + type = "application/json"; } - else { - res.write (JSON.stringify (content)); - } - res.statusCode = status; - res.end (); + res.writeHead (status, { + "Content-Type": type, + "Content-Length": content.length + }).end (content); }; http.createServer (function (req, res) {