Skip to content

Commit dafe56c

Browse files
authored
fix: default Content-Type to x-www-form-urlencoded when importing curl POST with body (hoppscotch#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
1 parent f929b81 commit dafe56c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/hoppscotch-common/src/helpers/curl/curlparser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ export const parseCurlCommand = (curlCommand: string) => {
132132
danglingParams = [...danglingParams, ...newQueries.danglingParams]
133133
hasBodyBeenParsed = true
134134
} else if (
135-
rawContentType.includes("application/x-www-form-urlencoded") &&
135+
(rawContentType.includes("application/x-www-form-urlencoded") ||
136+
/**
137+
* When using the -d option with curl for a POST operation,
138+
* curl includes a default header: Content-Type: application/x-www-form-urlencoded.
139+
* https://everything.curl.dev/http/post/content-type.html
140+
*/
141+
(!rawContentType &&
142+
method === "POST" &&
143+
rawData &&
144+
rawData.length > 0)) &&
136145
!!pairs &&
137146
Array.isArray(rawData)
138147
) {

0 commit comments

Comments
 (0)