fix: urlencoded form evaluation issues
This commit is contained in:
9
packages/hoppscotch-app/helpers/functional/debug.ts
Normal file
9
packages/hoppscotch-app/helpers/functional/debug.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Logs the current value and returns the same value
|
||||
* @param x The value to log
|
||||
* @returns The parameter `x` passed to this
|
||||
*/
|
||||
export const trace = <T>(x: T) => {
|
||||
console.log(x)
|
||||
return x
|
||||
}
|
||||
7
packages/hoppscotch-app/helpers/functional/record.ts
Normal file
7
packages/hoppscotch-app/helpers/functional/record.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const tupleToRecord = <
|
||||
KeyType extends string | number | symbol,
|
||||
ValueType
|
||||
>(
|
||||
tuples: [KeyType, ValueType][]
|
||||
): Record<KeyType, ValueType> =>
|
||||
(Object.assign as any)(...tuples.map(([key, val]) => ({ [key]: val })))
|
||||
@@ -122,8 +122,9 @@ const axiosWithoutProxy: NetworkStrategy = (req) =>
|
||||
)
|
||||
|
||||
const axiosStrategy: NetworkStrategy = (req) =>
|
||||
settingsStore.value.PROXY_ENABLED
|
||||
? axiosWithProxy(req)
|
||||
: axiosWithoutProxy(req)
|
||||
pipe(
|
||||
req,
|
||||
settingsStore.value.PROXY_ENABLED ? axiosWithProxy : axiosWithoutProxy
|
||||
)
|
||||
|
||||
export default axiosStrategy
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import * as RA from "fp-ts/ReadonlyArray"
|
||||
import * as S from "fp-ts/string"
|
||||
import qs from "qs"
|
||||
import { pipe, flow } from "fp-ts/function"
|
||||
import { combineLatest, Observable } from "rxjs"
|
||||
import { map } from "rxjs/operators"
|
||||
import {
|
||||
@@ -6,6 +10,7 @@ import {
|
||||
HoppRESTRequest,
|
||||
} from "@hoppscotch/data"
|
||||
import { parseTemplateString, parseBodyEnvVariables } from "../templating"
|
||||
import { tupleToRecord } from "../functional/record"
|
||||
import { Environment, getGlobalVariables } from "~/newstore/environments"
|
||||
|
||||
export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
|
||||
@@ -58,6 +63,25 @@ function getFinalBodyFromRequest(
|
||||
return null
|
||||
}
|
||||
|
||||
if (request.body.contentType === "application/x-www-form-urlencoded") {
|
||||
return pipe(
|
||||
request.body.body,
|
||||
S.split("\n"),
|
||||
RA.map(
|
||||
flow(
|
||||
// Define how each lines are parsed
|
||||
|
||||
S.split(":"), // Split by ":"
|
||||
RA.map(S.trim), // Remove trailing spaces in key/value begins and ends
|
||||
([key, value]) => [key, value ?? ""] as [string, string] // Add a default empty by default
|
||||
)
|
||||
),
|
||||
RA.toArray,
|
||||
tupleToRecord, // Convert the tuple to a record
|
||||
qs.stringify
|
||||
)
|
||||
}
|
||||
|
||||
if (request.body.contentType === "multipart/form-data") {
|
||||
const formData = new FormData()
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
"openapi-types": "^10.0.0",
|
||||
"paho-mqtt": "^1.1.0",
|
||||
"postman-collection": "^4.1.1",
|
||||
"qs": "^6.10.3",
|
||||
"rxjs": "^7.5.2",
|
||||
"socket.io-client-v2": "npm:socket.io-client@^2.4.0",
|
||||
"socket.io-client-v3": "npm:socket.io-client@^3.1.3",
|
||||
|
||||
Reference in New Issue
Block a user