+
+ 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);
+ }
+ } else {
+ next(undefined);
+ }
+ }
+
+ private validateRawDataRequest(rawData: RawData): ProtocolRequest {
+ // logger.debug(
+ // `${this.logPrefix(
+ // moduleName,
+ // 'validateRawDataRequest'
+ // )} Raw data received in string format: ${rawData.toString()}`
+ // );
+
+ const request = JSON.parse(rawData.toString()) as ProtocolRequest;
+
+ if (Array.isArray(request) === false) {
+ throw new BaseError('UI protocol request is not an array');
+ }
+
+ if (request.length !== 3) {
+ throw new BaseError('UI protocol request is malformed');
+ }
+
+ return request;
+ }