From 1c172a44cf0a4aee4cefd805876ce21a9d8a707a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 12 May 2020 08:14:20 +0200 Subject: [PATCH] lib: remove mode variable from getMode Currently, the mode variable in getMode is set to 'unknown' but this will never get returned as the else clause will throw a TypeError if the detected mode (from the passed-in headers) is not structured or binary. This commit suggests simplifying the getMode function and removes the mode variable. Signed-off-by: Daniel Bevenius --- lib/bindings/http/http_receiver.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bindings/http/http_receiver.js b/lib/bindings/http/http_receiver.js index 866c7966..c121cd30 100644 --- a/lib/bindings/http/http_receiver.js +++ b/lib/bindings/http/http_receiver.js @@ -42,16 +42,14 @@ class HTTPReceiver { } function getMode(headers) { - let mode = "unknown"; const contentType = headers[HEADER_CONTENT_TYPE]; if (contentType && contentType.startsWith(MIME_CE)) { - mode = "structured"; - } else if (headers[BINARY_HEADERS_1.ID]) { - mode = "binary"; - } else { - throw new TypeError("no cloud event detected"); + return "structured"; + } + if (headers[BINARY_HEADERS_1.ID]) { + return "binary"; } - return mode; + throw new TypeError("no cloud event detected"); } function getVersion(mode, headers, body) {