Skip to content

Commit

Permalink
chore: show warning for interceptors not supporting binary data (#4566)
Browse files Browse the repository at this point in the history
Co-authored-by: jamesgeorge007 <[email protected]>
  • Loading branch information
CuriousCorrelation and jamesgeorge007 authored Nov 27, 2024
1 parent a66771b commit 2251558
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/hoppscotch-common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -302,8 +304,6 @@ export class AgentInterceptorService extends Service implements Interceptor {

public proxyInfo = ref<RequestDef["proxy"]>(undefined)

public supportsDigestAuth = true

override onServiceInit() {
// Register the Root UI Extension
this.uiExtensionService.addRootUIExtension(AgentRootUIExtension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand Down
20 changes: 13 additions & 7 deletions packages/hoppscotch-common/src/services/interceptor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,22 @@ export type Interceptor<Err extends InterceptorError = InterceptorError> = {

/**
* 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.
Expand Down Expand Up @@ -141,12 +153,6 @@ export type Interceptor<Err extends InterceptorError = InterceptorError> = {
* @param request The request to run the interceptor on.
*/
runRequest: (request: AxiosRequestConfig) => RequestRunResult<Err>

/**
* 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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -277,8 +279,6 @@ export class NativeInterceptorService extends Service implements Interceptor {
public validateCerts = ref(true)
public proxyInfo = ref<RequestDef["proxy"]>(undefined)

public supportsDigestAuth = true

override onServiceInit() {
// Load SSL Validation
const persistedValidateSSL: unknown = JSON.parse(
Expand Down

0 comments on commit 2251558

Please sign in to comment.