Skip to content

Commit 4f07671

Browse files
committed
Use multiple --data flags for curl
For application/x-www-form-urlencoded requests, Curl supports setting multiple --data flags instead of building a querystring for use in a single entry. - Handle application/x-www-form-urlencoded in curl target - Update test fixture
1 parent c8b1da4 commit 4f07671

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/targets/shell/curl.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ module.exports = function (source, options) {
5454
})
5555
break
5656

57+
case 'application/x-www-form-urlencoded':
58+
if (source.postData.params) {
59+
source.postData.params.map(function (param) {
60+
code.push(
61+
'%s %s', opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
62+
helpers.quote(util.format('%s=%s', param.name, param.value))
63+
)
64+
})
65+
} else {
66+
code.push(
67+
'%s %s', opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
68+
helpers.escape(helpers.quote(source.postData.text))
69+
)
70+
}
71+
break
72+
5773
default:
5874
// raw request body
5975
if (source.postData.text) {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
curl --request POST \
22
--url http://mockbin.com/har \
33
--header 'content-type: application/x-www-form-urlencoded' \
4-
--data 'foo=bar&hello=world'
4+
--data foo=bar \
5+
--data hello=world

0 commit comments

Comments
 (0)