X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2FUIHttpServer.ts;h=ce52ed4b5dd432a9c9035bbdc0eac01c7a422e4f;hb=2a61222f10b8abdb97d022790e4ad543c4bd1d6c;hp=280f1d38040d71ab7151d1c33fa69b93f0977189;hpb=eb3abc4fe41400debcf894e53f91937498e77571;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 280f1d38..ce52ed4b 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -49,10 +49,11 @@ export default class UIHttpServer extends AbstractUIServer { public sendResponse(response: ProtocolResponse): void { const [uuid, payload] = response; - const statusCode = this.responseStatusToStatusCode(payload.status); if (this.responseHandlers.has(uuid) === true) { const { res } = this.responseHandlers.get(uuid); - res.writeHead(statusCode, { 'Content-Type': 'application/json' }); + res.writeHead(this.responseStatusToStatusCode(payload.status), { + 'Content-Type': 'application/json', + }); res.write(JSON.stringify(payload)); res.end(); this.responseHandlers.delete(uuid); @@ -71,7 +72,7 @@ export default class UIHttpServer extends AbstractUIServer { } private requestListener(req: IncomingMessage, res: ServerResponse): void { - if (this.isBasicAuthEnabled() === true && this.isValidBasicAuth(req) === false) { + if (this.authenticate(req) === false) { res.setHeader('Content-Type', 'text/plain'); res.setHeader('WWW-Authenticate', 'Basic realm=users'); res.writeHead(StatusCodes.UNAUTHORIZED); @@ -128,6 +129,16 @@ export default class UIHttpServer extends AbstractUIServer { } } + private authenticate(req: IncomingMessage): boolean { + if (this.isBasicAuthEnabled() === true) { + if (this.isValidBasicAuth(req) === true) { + return true; + } + return false; + } + return true; + } + private responseStatusToStatusCode(status: ResponseStatus): StatusCodes { switch (status) { case ResponseStatus.SUCCESS: