From: Jérôme Benoit Date: Fri, 9 Sep 2022 05:31:44 +0000 (+0200) Subject: UI Server: fix 'write after end' issue for real X-Git-Tag: v1.1.72~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b2e2c274c2f60fb80857640f0399f76cf65e169f;p=e-mobility-charging-stations-simulator.git UI Server: fix 'write after end' issue for real Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 7dfff0ad..822244f9 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -42,10 +42,11 @@ export default class UIHttpServer extends AbstractUIServer { try { if (this.responseHandlers.has(uuid) === true) { const res = this.responseHandlers.get(uuid) as ServerResponse; - res.writeHead(this.responseStatusToStatusCode(payload.status), { - 'Content-Type': 'application/json', - }); - res.end(JSON.stringify(payload)); + res + .writeHead(this.responseStatusToStatusCode(payload.status), { + 'Content-Type': 'application/json', + }) + .end(JSON.stringify(payload)); this.responseHandlers.delete(uuid); } else { logger.error( @@ -70,12 +71,14 @@ export default class UIHttpServer extends AbstractUIServer { private requestListener(req: IncomingMessage, res: ServerResponse): void { this.authenticate(req, (err) => { if (err) { - res.setHeader('Content-Type', 'text/plain'); - res.setHeader('WWW-Authenticate', 'Basic realm=users'); - res.writeHead(StatusCodes.UNAUTHORIZED); - res.end(`${StatusCodes.UNAUTHORIZED} Unauthorized`); + res + .writeHead(StatusCodes.UNAUTHORIZED, { + 'Content-Type': 'text/plain', + 'WWW-Authenticate': 'Basic realm=users', + }) + .end(`${StatusCodes.UNAUTHORIZED} Unauthorized`) + .destroy(); req.destroy(); - res.destroy(); } }); // Expected request URL pathname: /ui/:version/:procedureName