From e970fc69c16674256112d00ec16569db0b49d23b Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 28 Apr 2024 21:54:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Apply=20custom=20headers=20to=20?= =?UTF-8?q?fetch=20request=20(#1549)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mixins/WidgetMixin.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mixins/WidgetMixin.js b/src/mixins/WidgetMixin.js index e183000b..507eaacc 100644 --- a/src/mixins/WidgetMixin.js +++ b/src/mixins/WidgetMixin.js @@ -105,10 +105,18 @@ const WidgetMixin = { const method = protocol || 'GET'; const url = this.useProxy ? this.proxyReqEndpoint : endpoint; const data = JSON.stringify(body || {}); + const CustomHeaders = options || {}; - const headers = new Headers(this.useProxy - ? ({ ...CustomHeaders, 'Target-URL': endpoint }) - : CustomHeaders); + const headers = new Headers(); + + // If using a proxy, set the 'Target-URL' header + if (this.useProxy) { + headers.append('Target-URL', endpoint); + } + // Apply widget-specific custom headers + Object.entries(CustomHeaders).forEach(([key, value]) => { + headers.append(key, value); + }); // If the request is a GET, delete the body const bodyContent = method.toUpperCase() === 'GET' ? undefined : data;