From dafe56cfe924ff0f52ef058d1a8c4f8cb07fc8dd Mon Sep 17 00:00:00 2001 From: shuaixr <1025sxr@gmail.com> Date: Wed, 7 May 2025 01:55:45 -0700 Subject: [PATCH] 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 --- .../hoppscotch-common/src/helpers/curl/curlparser.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts index 9617d8fb..0205ec8f 100644 --- a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts +++ b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts @@ -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) ) {