}
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:
}
}
- private authenticate(req: IncomingMessage, next: (err: Error) => void): void {
+ private authenticate(req: IncomingMessage, next: (err?: Error) => void): void {
if (this.isBasicAuthEnabled() === true) {
if (this.isValidBasicAuth(req) === false) {
next(new Error('Unauthorized'));
} else {
- next(undefined);
+ next();
}
} else {
- next(undefined);
+ next();
}
}