mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Fix multipart newlines for Windows
This commit is contained in:
parent
e8c964dd83
commit
af2bbca356
@ -20,10 +20,10 @@ describe('buildMultipart()', () => {
|
||||
`${boundary}`,
|
||||
'Content-Disposition: form-data; name="multi-line"',
|
||||
'',
|
||||
'Hello',
|
||||
'World!',
|
||||
`${boundary}--`
|
||||
].join('\n'));
|
||||
'Hello\nWorld!',
|
||||
`${boundary}--`,
|
||||
''
|
||||
].join('\r\n'));
|
||||
});
|
||||
|
||||
it('builds with file', async () => {
|
||||
@ -44,15 +44,14 @@ describe('buildMultipart()', () => {
|
||||
'Content-Disposition: form-data; name="file"; filename="testfile.txt"',
|
||||
'Content-Type: text/plain',
|
||||
'',
|
||||
'Hello World!',
|
||||
'',
|
||||
'How are you?',
|
||||
'Hello World!\n\nHow are you?',
|
||||
`${boundary}`,
|
||||
'Content-Disposition: form-data; name="baz"',
|
||||
'',
|
||||
'qux',
|
||||
`${boundary}--`
|
||||
].join('\n'));
|
||||
`${boundary}--`,
|
||||
''
|
||||
].join('\r\n'));
|
||||
});
|
||||
|
||||
it('skips entries with no name or value', async () => {
|
||||
@ -73,7 +72,8 @@ describe('buildMultipart()', () => {
|
||||
'Content-Disposition: form-data; name="foo"',
|
||||
'',
|
||||
'',
|
||||
`${boundary}--`
|
||||
].join('\n'));
|
||||
`${boundary}--`,
|
||||
''
|
||||
].join('\r\n'));
|
||||
});
|
||||
});
|
||||
|
@ -324,8 +324,9 @@ describe('actuallySend()', () => {
|
||||
'Content-Disposition: form-data; name="a"',
|
||||
'',
|
||||
'AA',
|
||||
'------------------------X-INSOMNIA-BOUNDARY--'
|
||||
].join('\n'));
|
||||
'------------------------X-INSOMNIA-BOUNDARY--',
|
||||
''
|
||||
].join('\r\n'));
|
||||
|
||||
expect(body.options).toEqual({
|
||||
POST: 1,
|
||||
@ -339,7 +340,7 @@ describe('actuallySend()', () => {
|
||||
'Expect: ',
|
||||
'Transfer-Encoding: '
|
||||
],
|
||||
INFILESIZE_LARGE: 299,
|
||||
INFILESIZE_LARGE: 310,
|
||||
NOPROGRESS: false,
|
||||
PROXY: '',
|
||||
TIMEOUT_MS: 0,
|
||||
|
@ -7,6 +7,7 @@ import type {RequestBodyParameter} from '../models/request';
|
||||
export function buildMultipart (params: Array<RequestBodyParameter>): {boundary: string, body: Buffer} {
|
||||
const buffers = [];
|
||||
const boundary = '------------------------X-INSOMNIA-BOUNDARY';
|
||||
const lineBreak = '\r\n';
|
||||
|
||||
const add = (v: Buffer | string) => {
|
||||
if (typeof v === 'string') {
|
||||
@ -24,7 +25,8 @@ export function buildMultipart (params: Array<RequestBodyParameter>): {boundary:
|
||||
continue;
|
||||
}
|
||||
|
||||
add(`${boundary}\n`);
|
||||
add(`${boundary}`);
|
||||
add(lineBreak);
|
||||
|
||||
if (param.type === 'file' && param.fileName) {
|
||||
const name = param.name || '';
|
||||
@ -33,21 +35,27 @@ export function buildMultipart (params: Array<RequestBodyParameter>): {boundary:
|
||||
add(
|
||||
'Content-Disposition: form-data; ' +
|
||||
`name="${name.replace(/"/g, '\\"')}"; ` +
|
||||
`filename="${path.basename(fileName).replace(/"/g, '\\"')}"\n`
|
||||
`filename="${path.basename(fileName).replace(/"/g, '\\"')}"`
|
||||
);
|
||||
add(`Content-Type: ${contentType}\n\n`);
|
||||
add(lineBreak);
|
||||
add(`Content-Type: ${contentType}`);
|
||||
add(lineBreak);
|
||||
add(lineBreak);
|
||||
add(fs.readFileSync(fileName));
|
||||
} else {
|
||||
const name = param.name || '';
|
||||
const value = param.value || '';
|
||||
add(`Content-Disposition: form-data; name="${name}"\n\n`);
|
||||
add(`Content-Disposition: form-data; name="${name}"`);
|
||||
add(lineBreak);
|
||||
add(lineBreak);
|
||||
add(value);
|
||||
}
|
||||
|
||||
add('\n');
|
||||
add(lineBreak);
|
||||
}
|
||||
|
||||
add(`${boundary}--`);
|
||||
add(lineBreak);
|
||||
|
||||
const body = Buffer.concat(buffers);
|
||||
return {boundary: boundary, body};
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "insomnia",
|
||||
"version": "5.9.0",
|
||||
"version": "5.9.1",
|
||||
"productName": "Insomnia",
|
||||
"longName": "Insomnia REST Client",
|
||||
"description": "Debug APIs like a human, not a robot",
|
||||
|
Loading…
Reference in New Issue
Block a user