Skip to content

Commit a23f21d

Browse files
authored
Merge pull request #771 from postmanlabs/fix/curl-data-binary-support
Added support for usage of --data-binary flag when using long format option for body type binary.
2 parents 3494492 + a779851 commit a23f21d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

codegens/curl/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ self = module.exports = {
201201
});
202202
break;
203203
case 'file':
204-
snippet += indent + form('-d', format);
204+
snippet += indent + (format ? '--data-binary' : '-d');
205205
snippet += ` ${quoteType}@${sanitize(body[body.mode].src, trim)}${quoteType}`;
206206
break;
207207
default:

codegens/curl/test/unit/convert.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,5 +1144,37 @@ describe('curl convert function', function () {
11441144
});
11451145
});
11461146
});
1147+
1148+
it('should use --data-binary when request body type is binary', function () {
1149+
var request = new Request({
1150+
'method': 'POST',
1151+
'header': [],
1152+
'body': {
1153+
'mode': 'file',
1154+
'file': {
1155+
'src': 'file-path/collection123.json'
1156+
}
1157+
},
1158+
'url': {
1159+
'raw': 'https://postman-echo.com/get',
1160+
'protocol': 'https',
1161+
'host': [
1162+
'postman-echo',
1163+
'com'
1164+
],
1165+
'path': [
1166+
'get'
1167+
]
1168+
}
1169+
});
1170+
1171+
convert(request, { longFormat: true }, function (error, snippet) {
1172+
if (error) {
1173+
expect.fail(null, null, error);
1174+
}
1175+
expect(snippet).to.be.a('string');
1176+
expect(snippet).to.include('--data-binary \'@file-path/collection123.json\'');
1177+
});
1178+
});
11471179
});
11481180
});

codegens/python-http.client/test/unit/converter.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ describe('Python-http.client converter', function () {
337337
});
338338

339339
it('should generate valid snippets when url uses http protocol', function () {
340-
var request = new sdk.Request({
340+
var request = new Request({
341341
'method': 'GET',
342342
'header': [],
343343
'url': {

0 commit comments

Comments
 (0)