fix: curl parser json detection issues (#2370)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
kyteinsky
2022-06-18 14:09:16 +05:30
committed by GitHub
parent 16be7c38f3
commit c1cc1ce295

View File

@@ -158,13 +158,10 @@ const getXMLBody = (rawData: string) =>
O.alt(() => O.some(rawData)) O.alt(() => O.some(rawData))
) )
const getFormattedJSON = (jsonString: string) => const getFormattedJSON = flow(
pipe(
jsonString.replaceAll('\\"', '"'),
safeParseJSON, safeParseJSON,
O.map((parsedJSON) => JSON.stringify(parsedJSON, null, 2)), O.map((parsedJSON) => JSON.stringify(parsedJSON, null, 2)),
O.getOrElse(() => "{ }"), O.getOrElse(() => "{ }")
O.of
) )
const getXWWWFormUrlEncodedBody = flow( const getXWWWFormUrlEncodedBody = flow(
@@ -191,7 +188,7 @@ export function parseBody(
case "application/ld+json": case "application/ld+json":
case "application/vnd.api+json": case "application/vnd.api+json":
case "application/json": case "application/json":
return getFormattedJSON(rawData) return O.some(getFormattedJSON(rawData))
case "application/x-www-form-urlencoded": case "application/x-www-form-urlencoded":
return getXWWWFormUrlEncodedBody(rawData) return getXWWWFormUrlEncodedBody(rawData)