From fb2b677fafdca8f90a926ca76a41edf43bda29a6 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Fri, 28 Mar 2025 17:52:45 +0530 Subject: [PATCH] fix: import bug with extension and agent interceptors (#4932) Co-authored-by: curiouscorrelation --- packages/hoppscotch-common/src/components.d.ts | 2 -- .../std/kernel-interceptors/agent/index.ts | 18 +++++++++++++++++- .../std/kernel-interceptors/extension/index.ts | 2 +- .../std/kernel-interceptors/native/index.ts | 18 +++++++++++++++++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 8d304cbf..4ea41f4a 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -205,7 +205,6 @@ declare module 'vue' { IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'] IconLucideArrowUpRight: typeof import('~icons/lucide/arrow-up-right')['default'] IconLucideBrush: typeof import('~icons/lucide/brush')['default'] - IconLucideCheck: typeof import('~icons/lucide/check')['default'] IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default'] IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] IconLucideCircleCheck: typeof import('~icons/lucide/circle-check')['default'] @@ -216,7 +215,6 @@ declare module 'vue' { IconLucideLayers: typeof import('~icons/lucide/layers')['default'] IconLucideListEnd: typeof import('~icons/lucide/list-end')['default'] IconLucideMinus: typeof import('~icons/lucide/minus')['default'] - IconLucidePlus: typeof import('~icons/lucide/plus')['default'] IconLucidePlusCircle: typeof import('~icons/lucide/plus-circle')['default'] IconLucideRss: typeof import('~icons/lucide/rss')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default'] diff --git a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts index 292469b1..9a377d42 100644 --- a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts +++ b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/agent/index.ts @@ -132,8 +132,24 @@ export class AgentKernelInterceptorService .join(";") } + const existingUserAgentHeader = Object.keys( + effectiveRequest.headers || {} + ).find((header) => header.toLowerCase() === "user-agent") + + // A temporary workaround to add a User-Agent header to the request + // This will be removed once the agent is updated to add User-Agent header by default + const effectiveRequestWithUserAgent = { + ...effectiveRequest, + headers: { + ...effectiveRequest.headers, + "User-Agent": existingUserAgentHeader + ? effectiveRequest.headers[existingUserAgentHeader] + : "HoppscotchKernel/0.1.0", + }, + } + const [nonceB16, encryptedReq] = await this.store.encryptRequest( - await relayRequestToNativeAdapter(effectiveRequest), + await relayRequestToNativeAdapter(effectiveRequestWithUserAgent), reqID ) diff --git a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/extension/index.ts b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/extension/index.ts index 7a733e2f..0c377203 100644 --- a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/extension/index.ts +++ b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/extension/index.ts @@ -276,7 +276,7 @@ export class ExtensionKernelInterceptorService await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({ url: request.url, method: request.method, - headers: request.headers, + headers: request.headers ?? {}, data: requestData, wantsBinary: true, }) diff --git a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/native/index.ts b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/native/index.ts index b356b899..f60977d1 100644 --- a/packages/hoppscotch-common/src/platform/std/kernel-interceptors/native/index.ts +++ b/packages/hoppscotch-common/src/platform/std/kernel-interceptors/native/index.ts @@ -83,7 +83,23 @@ export class NativeKernelInterceptorService .join(";") } - const relayExecution = Relay.execute(effectiveRequest) + const existingUserAgentHeader = Object.keys( + effectiveRequest.headers || {} + ).find((header) => header.toLowerCase() === "user-agent") + + // A temporary workaround to add a User-Agent header to the request + // This will be removed once the kernel/relay is updated to add User-Agent header by default + const effectiveRequestWithUserAgent = { + ...effectiveRequest, + headers: { + ...effectiveRequest.headers, + "User-Agent": existingUserAgentHeader + ? effectiveRequest.headers[existingUserAgentHeader] + : "HoppscotchKernel/0.1.0", + }, + } + + const relayExecution = Relay.execute(effectiveRequestWithUserAgent) const response = pipe(relayExecution.response, (promise) => promise.then((either) =>