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." "extention_not_enabled": "Extension not enabled."
}, },
"requestBody": { "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": { "layout": {

View File

@@ -271,7 +271,9 @@ export class AgentInterceptorService extends Service implements Interceptor {
public selectable = { type: "selectable" as const } public selectable = { type: "selectable" as const }
public supportsDigestAuth = true
public supportsCookies = true public supportsCookies = true
public supportsBinaryContentType = false
private interceptorService = this.bind(InterceptorService) private interceptorService = this.bind(InterceptorService)
private cookieJarService = this.bind(CookieJarService) private cookieJarService = this.bind(CookieJarService)
@@ -302,8 +304,6 @@ export class AgentInterceptorService extends Service implements Interceptor {
public proxyInfo = ref<RequestDef["proxy"]>(undefined) public proxyInfo = ref<RequestDef["proxy"]>(undefined)
public supportsDigestAuth = true
override onServiceInit() { override onServiceInit() {
// Register the Root UI Extension // Register the Root UI Extension
this.uiExtensionService.addRootUIExtension(AgentRootUIExtension) this.uiExtensionService.addRootUIExtension(AgentRootUIExtension)

View File

@@ -40,10 +40,14 @@ export class InterceptorsInspectorService extends Service implements Inspector {
const isBinaryBody = const isBinaryBody =
req.value.body.contentType === "application/octet-stream" req.value.body.contentType === "application/octet-stream"
// TODO: define the supported capabilities in the interceptor const currentInterceptor = this.interceptors.currentInterceptor.value
const isAgent = this.interceptors.currentInterceptorID.value === "agent"
if (isBinaryBody && isAgent) { // TODO: Maybe move feature determination/checking related things to interceptor system.
if (
isBinaryBody &&
currentInterceptor &&
currentInterceptor.supportsBinaryContentType === false
) {
return [ return [
{ {
isApplicable: true, isApplicable: true,
@@ -52,7 +56,7 @@ export class InterceptorsInspectorService extends Service implements Inspector {
text: { text: {
type: "text", type: "text",
text: this.t( text: this.t(
"inspections.requestBody.agent_doesnt_support_binary_body" "inspections.requestBody.active_interceptor_doesnt_support_binary_body"
), ),
}, },
locations: { locations: {

View File

@@ -104,10 +104,22 @@ export type Interceptor<Err extends InterceptorError = InterceptorError> = {
/** /**
* Defines whether the interceptor has support for cookies. * 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 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. * Defines what to render in the Interceptor section of the Settings page.
* Use this space to define interceptor specific settings. * 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. * @param request The request to run the interceptor on.
*/ */
runRequest: (request: AxiosRequestConfig) => RequestRunResult<Err> 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 selectable = { type: "selectable" as const }
public supportsCookies = true public supportsCookies = true
public supportsDigestAuth = true
public supportsBinaryContentType = false
private cookieJarService = this.bind(CookieJarService) private cookieJarService = this.bind(CookieJarService)
private persistenceService: PersistenceService = this.bind(PersistenceService) private persistenceService: PersistenceService = this.bind(PersistenceService)
@@ -277,8 +279,6 @@ export class NativeInterceptorService extends Service implements Interceptor {
public validateCerts = ref(true) public validateCerts = ref(true)
public proxyInfo = ref<RequestDef["proxy"]>(undefined) public proxyInfo = ref<RequestDef["proxy"]>(undefined)
public supportsDigestAuth = true
override onServiceInit() { override onServiceInit() {
// Load SSL Validation // Load SSL Validation
const persistedValidateSSL: unknown = JSON.parse( const persistedValidateSSL: unknown = JSON.parse(