fix: same key params are not overwritten to the last defined (#2299)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { AxiosRequestConfig } from "axios"
|
||||
import cloneDeep from "lodash/cloneDeep"
|
||||
import { NetworkResponse, NetworkStrategy } from "../network"
|
||||
import { browserIsChrome, browserIsFirefox } from "../utils/userAgent"
|
||||
|
||||
@@ -21,19 +23,43 @@ export const cancelRunningExtensionRequest = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const preProcessRequest = (req: AxiosRequestConfig): AxiosRequestConfig => {
|
||||
const reqClone = cloneDeep(req)
|
||||
|
||||
// If the parameters are URLSearchParams, inject them to URL instead
|
||||
// This prevents marshalling issues with structured cloning of URLSearchParams
|
||||
if (reqClone.params instanceof URLSearchParams) {
|
||||
try {
|
||||
const url = new URL(reqClone.url ?? "")
|
||||
|
||||
for (const [key, value] of reqClone.params.entries()) {
|
||||
url.searchParams.append(key, value)
|
||||
}
|
||||
|
||||
reqClone.url = url.toString()
|
||||
} catch (e) {}
|
||||
|
||||
reqClone.params = {}
|
||||
}
|
||||
|
||||
return reqClone
|
||||
}
|
||||
|
||||
const extensionStrategy: NetworkStrategy = (req) =>
|
||||
pipe(
|
||||
TE.Do,
|
||||
|
||||
TE.bind("processedReq", () => TE.of(preProcessRequest(req))),
|
||||
|
||||
// Storeing backup timing data in case the extension does not have that info
|
||||
TE.bind("backupTimeDataStart", () => TE.of(new Date().getTime())),
|
||||
|
||||
// Run the request
|
||||
TE.bind("response", () =>
|
||||
TE.bind("response", ({ processedReq }) =>
|
||||
TE.tryCatch(
|
||||
() =>
|
||||
window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({
|
||||
...req,
|
||||
...processedReq,
|
||||
wantsBinary: true,
|
||||
}) as Promise<NetworkResponse>,
|
||||
(err) => err as any
|
||||
|
||||
Reference in New Issue
Block a user