chore: show warning for interceptors not supporting binary data (#4566)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Shreyas
2024-11-27 16:53:30 +05:30
committed by GitHub
parent a66771bbd0
commit 22515582c5
5 changed files with 26 additions and 16 deletions

View File

@@ -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": {

View File

@@ -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<RequestDef["proxy"]>(undefined)
public supportsDigestAuth = true
override onServiceInit() {
// Register the Root UI Extension
this.uiExtensionService.addRootUIExtension(AgentRootUIExtension)

View File

@@ -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: {

View File

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

View File

@@ -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<RequestDef["proxy"]>(undefined)
public supportsDigestAuth = true
override onServiceInit() {
// Load SSL Validation
const persistedValidateSSL: unknown = JSON.parse(