feat: support for binary body (#4466)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -46,6 +46,9 @@ export type InspectorLocation =
|
||||
| {
|
||||
type: "response"
|
||||
}
|
||||
| {
|
||||
type: "body-content-type-header"
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines info about an inspector result so the UI can render it
|
||||
@@ -60,7 +63,7 @@ export interface InspectorResult {
|
||||
text: string
|
||||
apply: () => void
|
||||
}
|
||||
doc: {
|
||||
doc?: {
|
||||
text: string
|
||||
link: string
|
||||
}
|
||||
|
||||
@@ -100,7 +100,8 @@ export class EnvironmentInspectorService extends Service implements Inspector {
|
||||
position:
|
||||
locations.type === "url" ||
|
||||
locations.type === "body" ||
|
||||
locations.type === "response"
|
||||
locations.type === "response" ||
|
||||
locations.type === "body-content-type-header"
|
||||
? "key"
|
||||
: locations.position,
|
||||
index: index,
|
||||
@@ -222,7 +223,8 @@ export class EnvironmentInspectorService extends Service implements Inspector {
|
||||
position:
|
||||
locations.type === "url" ||
|
||||
locations.type === "body" ||
|
||||
locations.type === "response"
|
||||
locations.type === "response" ||
|
||||
locations.type === "body-content-type-header"
|
||||
? "key"
|
||||
: locations.position,
|
||||
index: index,
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Service } from "dioc"
|
||||
import { InspectionService, Inspector, InspectorResult } from ".."
|
||||
import { computed, Ref } from "vue"
|
||||
import {
|
||||
HoppRESTRequest,
|
||||
HoppRESTResponseOriginalRequest,
|
||||
} from "@hoppscotch/data"
|
||||
|
||||
import IconAlertCircle from "~icons/lucide/alert-circle"
|
||||
import { InterceptorService } from "~/services/interceptor.service"
|
||||
import { getI18n } from "~/modules/i18n"
|
||||
|
||||
/**
|
||||
* This inspector is responsible for inspecting the interceptor usage.
|
||||
*
|
||||
* NOTE: Initializing this service registers it as a inspector with the Inspection Service.
|
||||
*/
|
||||
export class InterceptorsInspectorService extends Service implements Inspector {
|
||||
public static readonly ID = "INTERCEPTORS_INSPECTOR_SERVICE"
|
||||
|
||||
inspectorID = "interceptors"
|
||||
|
||||
private t = getI18n()
|
||||
|
||||
private readonly inspection = this.bind(InspectionService)
|
||||
private readonly interceptors = this.bind(InterceptorService)
|
||||
|
||||
onServiceInit() {
|
||||
this.inspection.registerInspector(this)
|
||||
}
|
||||
|
||||
getInspections(
|
||||
req: Readonly<Ref<HoppRESTRequest | HoppRESTResponseOriginalRequest>>
|
||||
) {
|
||||
return computed((): InspectorResult[] => {
|
||||
const isBinaryBody =
|
||||
req.value.body.contentType === "application/octet-stream"
|
||||
|
||||
// TODO: define the supported capabilities in the interceptor
|
||||
const isAgent = this.interceptors.currentInterceptorID.value === "agent"
|
||||
|
||||
if (isBinaryBody && isAgent) {
|
||||
return [
|
||||
{
|
||||
isApplicable: true,
|
||||
icon: IconAlertCircle,
|
||||
severity: 2,
|
||||
text: {
|
||||
type: "text",
|
||||
text: this.t(
|
||||
"inspections.requestBody.agent_doesnt_support_binary_body"
|
||||
),
|
||||
},
|
||||
locations: {
|
||||
type: "body-content-type-header",
|
||||
},
|
||||
id: "interceptors-inspector-binary-agent-body-content-type-header",
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
return []
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user