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);
}
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);
}
}
+ 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: