From 04c287cc38ec7290e8becde13f1a330b891f1884 Mon Sep 17 00:00:00 2001 From: Curt Tudor Date: Tue, 8 Oct 2024 10:32:01 -0600 Subject: [PATCH] feat: do not process 'null' as a WebSocket event listener (#184) --- src/channel/channel.js | 5 +++-- src/context/context.js | 12 ++++++++---- src/http/ziti-websocket-wrapper.js | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/channel/channel.js b/src/channel/channel.js index 431417a..62e72b1 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -1153,13 +1153,14 @@ class ZitiChannel { if (len > 2000) { len = 2000; } - this._zitiContext.logger.trace("recv <- unencrypted_data (first 2000): %s", m1.substring(0, len)); + this._zitiContext.logger.trace("recv <- unencrypted_data (first 2000): ", m1.substring(0, len)); // // let dbgStr = m1.substring(0, len); // this._zitiContext.logger.trace("recv <- data (first 2000): %s", dbgStr); - } catch (e) { + } catch (e) { + // console.log('sodium.to_string error: ', e) } bodyView = unencrypted_data.message; diff --git a/src/context/context.js b/src/context/context.js index b76bdbb..7c9fe84 100644 --- a/src/context/context.js +++ b/src/context/context.js @@ -1267,7 +1267,7 @@ class ZitiContext extends EventEmitter { let config = result(find(this._services, function(obj) { return obj.name === name; }), 'config'); - this.logger.trace(`getServiceConfigByName() service[${name}] has config[${config}]`); + this.logger.trace(`getServiceConfigByName() service[${name}] has config: `, config); if (isUndefined(config)) { // Let any listeners know there are no configs associated with the given service, @@ -2337,9 +2337,13 @@ class ZitiContext extends EventEmitter { counter: request.counter }; - let body = res.pipe(new PassThrough( response_options )); - - let response = new HttpResponse(body, response_options); + let response; + if (isEqual(res.statusCode, 204)) { + response = new HttpResponse(null, response_options); + } else { + let body = res.pipe(new PassThrough( response_options )); + response = new HttpResponse(body, response_options); + } for (const hdr in response_options.headers) { if (response_options.headers.hasOwnProperty(hdr)) { diff --git a/src/http/ziti-websocket-wrapper.js b/src/http/ziti-websocket-wrapper.js index cf0b2d6..986ab4c 100644 --- a/src/http/ziti-websocket-wrapper.js +++ b/src/http/ziti-websocket-wrapper.js @@ -434,6 +434,7 @@ readyStates.forEach((readyState, i) => { * @public */ set(listener) { + if (isNull(listener) || isUndefined(listener)) { return; } const listeners = this.listeners(method); for (let i = 0; i < listeners.length; i++) { //