From 22515582c5a66593c0c902e2b9ca76e6bbadf2ac Mon Sep 17 00:00:00 2001 From: Shreyas Date: Wed, 27 Nov 2024 16:53:30 +0530 Subject: [PATCH] chore: show warning for interceptors not supporting binary data (#4566) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- packages/hoppscotch-common/locales/en.json | 2 +- .../platform/std/interceptors/agent/index.ts | 4 ++-- .../inspectors/interceptors.inspector.ts | 12 +++++++---- .../src/services/interceptor.service.ts | 20 ++++++++++++------- .../src/platform/interceptors/native/index.ts | 4 ++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 61a1978cf..3a38f57eb 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -576,7 +576,7 @@ "extention_not_enabled": "Extension not enabled." }, "requestBody": { - "agent_doesnt_support_binary_body": "Sending binary data via agent is not supported yet" + "active_interceptor_doesnt_support_binary_body": "Sending binary data via the current interceptor is not supported yet." } }, "layout": { diff --git a/packages/hoppscotch-common/src/platform/std/interceptors/agent/index.ts b/packages/hoppscotch-common/src/platform/std/interceptors/agent/index.ts index a27bce5e0..d6017beb0 100644 --- a/packages/hoppscotch-common/src/platform/std/interceptors/agent/index.ts +++ b/packages/hoppscotch-common/src/platform/std/interceptors/agent/index.ts @@ -271,7 +271,9 @@ export class AgentInterceptorService extends Service implements Interceptor { public selectable = { type: "selectable" as const } + public supportsDigestAuth = true public supportsCookies = true + public supportsBinaryContentType = false private interceptorService = this.bind(InterceptorService) private cookieJarService = this.bind(CookieJarService) @@ -302,8 +304,6 @@ export class AgentInterceptorService extends Service implements Interceptor { public proxyInfo = ref(undefined) - public supportsDigestAuth = true - override onServiceInit() { // Register the Root UI Extension this.uiExtensionService.addRootUIExtension(AgentRootUIExtension) diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/interceptors.inspector.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/interceptors.inspector.ts index b3cf0fe5f..140c72bbc 100644 --- a/packages/hoppscotch-common/src/services/inspection/inspectors/interceptors.inspector.ts +++ b/packages/hoppscotch-common/src/services/inspection/inspectors/interceptors.inspector.ts @@ -40,10 +40,14 @@ export class InterceptorsInspectorService extends Service implements Inspector { const isBinaryBody = req.value.body.contentType === "application/octet-stream" - // TODO: define the supported capabilities in the interceptor - const isAgent = this.interceptors.currentInterceptorID.value === "agent" + const currentInterceptor = this.interceptors.currentInterceptor.value - if (isBinaryBody && isAgent) { + // TODO: Maybe move feature determination/checking related things to interceptor system. + if ( + isBinaryBody && + currentInterceptor && + currentInterceptor.supportsBinaryContentType === false + ) { return [ { isApplicable: true, @@ -52,7 +56,7 @@ export class InterceptorsInspectorService extends Service implements Inspector { text: { type: "text", text: this.t( - "inspections.requestBody.agent_doesnt_support_binary_body" + "inspections.requestBody.active_interceptor_doesnt_support_binary_body" ), }, locations: { diff --git a/packages/hoppscotch-common/src/services/interceptor.service.ts b/packages/hoppscotch-common/src/services/interceptor.service.ts index 25a5889fd..629240f69 100644 --- a/packages/hoppscotch-common/src/services/interceptor.service.ts +++ b/packages/hoppscotch-common/src/services/interceptor.service.ts @@ -104,10 +104,22 @@ export type Interceptor = { /** * Defines whether the interceptor has support for cookies. - * If this field is undefined, it is assumed as not supporting cookies. + * If this field is undefined, it is assumed as *not supporting* cookies. */ supportsCookies?: boolean + /** + * Defines whether the interceptor has support for Digest Auth. + * If this field is undefined, it is assumed as *not supporting* the Digest Auth type. + */ + supportsDigestAuth?: boolean + + /** + * Defines whether the interceptor has support for Binary (file) content type. + * If this field is undefined, it is assumed as *supporting* the Binary content type. + */ + supportsBinaryContentType?: boolean + /** * Defines what to render in the Interceptor section of the Settings page. * Use this space to define interceptor specific settings. @@ -141,12 +153,6 @@ export type Interceptor = { * @param request The request to run the interceptor on. */ runRequest: (request: AxiosRequestConfig) => RequestRunResult - - /** - * Defines whether the interceptor has support for Digest Auth. - * If this field is undefined, it is assumed as not supporting the Digest Auth type. - */ - supportsDigestAuth?: boolean } /** diff --git a/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native/index.ts b/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native/index.ts index c6f08cf8d..bad33e961 100644 --- a/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native/index.ts +++ b/packages/hoppscotch-selfhost-desktop/src/platform/interceptors/native/index.ts @@ -260,6 +260,8 @@ export class NativeInterceptorService extends Service implements Interceptor { public selectable = { type: "selectable" as const } public supportsCookies = true + public supportsDigestAuth = true + public supportsBinaryContentType = false private cookieJarService = this.bind(CookieJarService) private persistenceService: PersistenceService = this.bind(PersistenceService) @@ -277,8 +279,6 @@ export class NativeInterceptorService extends Service implements Interceptor { public validateCerts = ref(true) public proxyInfo = ref(undefined) - public supportsDigestAuth = true - override onServiceInit() { // Load SSL Validation const persistedValidateSSL: unknown = JSON.parse(