fix: urlencoded body params being improper
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import * as RA from "fp-ts/ReadonlyArray"
|
||||||
|
import * as S from "fp-ts/string"
|
||||||
|
import { pipe, flow } from "fp-ts/function"
|
||||||
import * as Har from "har-format"
|
import * as Har from "har-format"
|
||||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { FieldEquals, objectFieldIncludes } from "../typeutils"
|
import { FieldEquals, objectFieldIncludes } from "../typeutils"
|
||||||
@@ -33,16 +36,24 @@ const buildHarPostParams = (
|
|||||||
): Har.Param[] => {
|
): Har.Param[] => {
|
||||||
// URL Encoded strings have a string style of contents
|
// URL Encoded strings have a string style of contents
|
||||||
if (req.body.contentType === "application/x-www-form-urlencoded") {
|
if (req.body.contentType === "application/x-www-form-urlencoded") {
|
||||||
return req.body.body
|
return pipe(
|
||||||
.split("&") // Split by separators
|
req.body.body,
|
||||||
.map((keyValue) => {
|
S.split("\n"),
|
||||||
const [key, value] = keyValue.split("=")
|
RA.map(
|
||||||
|
flow(
|
||||||
|
// Define how each lines are parsed
|
||||||
|
|
||||||
return {
|
S.split(":"), // Split by ":"
|
||||||
name: key,
|
RA.map(S.trim), // Remove trailing spaces in key/value begins and ends
|
||||||
value,
|
([key, value]) => ({
|
||||||
}
|
// Convert into a proper key value definition
|
||||||
})
|
name: key,
|
||||||
|
value: value ?? "", // Value can be undefined (if no ":" is present)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
),
|
||||||
|
RA.toArray
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// FormData has its own format
|
// FormData has its own format
|
||||||
return req.body.body.flatMap((entry) => {
|
return req.body.body.flatMap((entry) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user