fix(request): multipart payload not working while using proxy
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
|
import { v4 } from "uuid"
|
||||||
import { decodeB64StringToArrayBuffer } from "../utils/b64"
|
import { decodeB64StringToArrayBuffer } from "../utils/b64"
|
||||||
import { settingsStore } from "~/newstore/settings"
|
import { settingsStore } from "~/newstore/settings"
|
||||||
import { JsonFormattedError } from "~/helpers/utils/JsonFormattedError"
|
import { JsonFormattedError } from "~/helpers/utils/JsonFormattedError"
|
||||||
@@ -14,13 +15,25 @@ export const cancelRunningAxiosRequest = () => {
|
|||||||
|
|
||||||
const axiosWithProxy = async (req) => {
|
const axiosWithProxy = async (req) => {
|
||||||
try {
|
try {
|
||||||
|
let proxyReqPayload = {
|
||||||
|
...req,
|
||||||
|
wantsBinary: true,
|
||||||
|
}
|
||||||
|
const headers = {}
|
||||||
|
if (req.data instanceof FormData) {
|
||||||
|
const key = `proxyRequestData-${v4()}` // generate UniqueKey
|
||||||
|
headers["multipart-part-key"] = key
|
||||||
|
|
||||||
|
const formData = proxyReqPayload.data
|
||||||
|
proxyReqPayload.data = "" // discard formData
|
||||||
|
formData.append(key, JSON.stringify(proxyReqPayload)) // append axiosRequest to form
|
||||||
|
proxyReqPayload = formData
|
||||||
|
}
|
||||||
const { data } = await axios.post(
|
const { data } = await axios.post(
|
||||||
settingsStore.value.PROXY_URL || "https://proxy.hoppscotch.io",
|
settingsStore.value.PROXY_URL || "https://proxy.hoppscotch.io",
|
||||||
|
proxyReqPayload,
|
||||||
{
|
{
|
||||||
...req,
|
headers,
|
||||||
wantsBinary: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cancelToken: cancelSource.token,
|
cancelToken: cancelSource.token,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
"acorn": "^8.5.0",
|
"acorn": "^8.5.0",
|
||||||
"acorn-walk": "^8.2.0",
|
"acorn-walk": "^8.2.0",
|
||||||
"axios": "^0.22.0",
|
"axios": "^0.22.0",
|
||||||
|
"uuid": "8.3.2",
|
||||||
"codemirror": "^5.63.1",
|
"codemirror": "^5.63.1",
|
||||||
"codemirror-theme-github": "^1.0.0",
|
"codemirror-theme-github": "^1.0.0",
|
||||||
"core-js": "^3.18.2",
|
"core-js": "^3.18.2",
|
||||||
@@ -119,4 +120,4 @@
|
|||||||
"vue-jest": "^3.0.7",
|
"vue-jest": "^3.0.7",
|
||||||
"worker-loader": "^3.0.8"
|
"worker-loader": "^3.0.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -97,6 +97,7 @@ importers:
|
|||||||
ts-jest: ^27.0.5
|
ts-jest: ^27.0.5
|
||||||
typescript: ^4.4.3
|
typescript: ^4.4.3
|
||||||
unplugin-vue2-script-setup: ^0.6.11
|
unplugin-vue2-script-setup: ^0.6.11
|
||||||
|
uuid: 8.3.2
|
||||||
vue-apollo: ^3.0.8
|
vue-apollo: ^3.0.8
|
||||||
vue-cli-plugin-apollo: ^0.22.2
|
vue-cli-plugin-apollo: ^0.22.2
|
||||||
vue-functional-data-merge: ^3.1.0
|
vue-functional-data-merge: ^3.1.0
|
||||||
@@ -144,6 +145,7 @@ importers:
|
|||||||
socketio-wildcard: 2.0.0
|
socketio-wildcard: 2.0.0
|
||||||
splitpanes: 2.3.8
|
splitpanes: 2.3.8
|
||||||
tern: 0.24.3
|
tern: 0.24.3
|
||||||
|
uuid: 8.3.2
|
||||||
vue-apollo: 3.0.8_graphql-tag@2.12.5
|
vue-apollo: 3.0.8_graphql-tag@2.12.5
|
||||||
vue-cli-plugin-apollo: 0.22.2_typescript@4.4.3
|
vue-cli-plugin-apollo: 0.22.2_typescript@4.4.3
|
||||||
vue-functional-data-merge: 3.1.0
|
vue-functional-data-merge: 3.1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user