Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,26 @@ describe('curly bracket encoding', () => {
expect(result).toContain('%7B%22categories%22'); // Query parameter curly brackets should be encoded
});
});

describe('application/octet-stream body', () => {
const harWithFile = {
method: 'POST',
url: 'https://todos.stoplight.io/todos',
httpVersion: 'HTTP/1.1',
cookies: [],
headers: [{ name: 'Content-Type', value: 'application/octet-stream' }],
queryString: [],
postData: {
mimeType: 'application/octet-stream',
text: '@some-file.bin',
},
headersSize: -1,
bodySize: -1,
};

it('should send the file unmodified with --data-binary in curl', async () => {
const result = await convertRequestToSample('shell', 'curl', harWithFile);

expect(result).toContain('--data-binary @some-file.bin');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const convertRequestToSample = async (

try {
const snippet = new HTTPSnippet(request);
let converted = await snippet.convert(language, library);
// Makes cURL use --data-binary, as --data strips newlines and null bytes from the uploaded file
const options = request.postData?.mimeType === 'application/octet-stream' ? { binary: true } : undefined;
let converted = await snippet.convert(language, library, options);

if (Array.isArray(converted)) {
converted = converted[0];
Expand Down