fix: default Content-Type to x-www-form-urlencoded when importing curl POST with body (#5040)

fix: handle missing Content-Type when importing curl POST

When importing a curl POST request with a body and no explicit
Content-Type, default to `application/x-www-form-urlencoded`
to match curl's behavior.

Reference: https://everything.curl.dev/http/post/content-type.html
This commit is contained in:
shuaixr 2025-05-07 01:55:45 -07:00 committed by GitHub
parent f929b8122b
commit dafe56cfe9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -132,7 +132,16 @@ export const parseCurlCommand = (curlCommand: string) => {
danglingParams = [...danglingParams, ...newQueries.danglingParams]
hasBodyBeenParsed = true
} else if (
rawContentType.includes("application/x-www-form-urlencoded") &&
(rawContentType.includes("application/x-www-form-urlencoded") ||
/**
* When using the -d option with curl for a POST operation,
* curl includes a default header: Content-Type: application/x-www-form-urlencoded.
* https://everything.curl.dev/http/post/content-type.html
*/
(!rawContentType &&
method === "POST" &&
rawData &&
rawData.length > 0)) &&
!!pairs &&
Array.isArray(rawData)
) {