larvitreqparser 0.4.13 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -1
- package/.github/workflows/ci.yml +14 -0
- package/README.md +1 -2
- package/index.js +15 -15
- package/package.json +12 -13
- package/renovate.json +2 -7
- package/test/test.js +93 -134
- package/.travis.yml +0 -14
package/.eslintrc
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: larvitreqparser CI
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
uses: larvit/standards/.github/workflows/test.yml@master
|
|
8
|
+
|
|
9
|
+
publish:
|
|
10
|
+
if: github.ref == 'refs/heads/master'
|
|
11
|
+
needs: test
|
|
12
|
+
uses: larvit/standards/.github/workflows/publish.yml@master
|
|
13
|
+
secrets:
|
|
14
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
[](https://coveralls.io/github/larvit/larvitreqparser)
|
|
1
|
+
[](https://github.com/larvit/larvitreqparser/actions)
|
|
3
2
|
|
|
4
3
|
# Request parser middleware
|
|
5
4
|
|
package/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const topLogPrefix = 'larvitreqparser: ./index.js: ';
|
|
4
4
|
const EventEmitter = require('events').EventEmitter;
|
|
5
5
|
const Readable = require('stream').Readable;
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const { Log } = require('larvitutils');
|
|
7
|
+
const uuidLib = require('uuid');
|
|
8
|
+
const busboy = require('busboy');
|
|
9
9
|
const async = require('async');
|
|
10
10
|
const url = require('url');
|
|
11
11
|
const qs = require('qs');
|
|
@@ -28,7 +28,7 @@ function ReqParser(options) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (!that.options.log) {
|
|
31
|
-
that.options.log = new
|
|
31
|
+
that.options.log = new Log();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (!that.options.fs) {
|
|
@@ -96,7 +96,7 @@ ReqParser.prototype.parse = function parse(req, res, cb) {
|
|
|
96
96
|
const that = this;
|
|
97
97
|
|
|
98
98
|
if (!req.uuid) {
|
|
99
|
-
req.uuid =
|
|
99
|
+
req.uuid = uuidLib.v4();
|
|
100
100
|
}
|
|
101
101
|
req.reqParser = {};
|
|
102
102
|
|
|
@@ -138,7 +138,7 @@ ReqParser.prototype.parse = function parse(req, res, cb) {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
141
|
-
const
|
|
141
|
+
const bb = busboy(this.busboyOptions);
|
|
142
142
|
const logPrefix = topLogPrefix + 'parseFormMultipart() - reqUuid: ' + req.uuid + ' - ';
|
|
143
143
|
const that = this;
|
|
144
144
|
|
|
@@ -147,12 +147,12 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
|
147
147
|
req.formFields = {};
|
|
148
148
|
req.formFiles = {};
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
bb.on('file', function (fieldName, file, info) {
|
|
151
151
|
const formFile = {};
|
|
152
152
|
|
|
153
|
-
formFile.filename = filename;
|
|
154
|
-
formFile.encoding = encoding;
|
|
155
|
-
formFile.mimetype =
|
|
153
|
+
formFile.filename = info.filename;
|
|
154
|
+
formFile.encoding = info.encoding;
|
|
155
|
+
formFile.mimetype = info.mimeType;
|
|
156
156
|
|
|
157
157
|
if (that.options.storage === 'memory') {
|
|
158
158
|
formFile.buffer = [];
|
|
@@ -161,7 +161,7 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
|
161
161
|
formFile.buffer.push(data);
|
|
162
162
|
});
|
|
163
163
|
} else {
|
|
164
|
-
formFile.path = that.storage + '/' +
|
|
164
|
+
formFile.path = that.storage + '/' + uuidLib.v4();
|
|
165
165
|
formFile.writeStream = that.fs.createWriteStream(formFile.path);
|
|
166
166
|
file.pipe(formFile.writeStream);
|
|
167
167
|
formFile.writeStream.on('close', function () {
|
|
@@ -186,11 +186,11 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
|
|
189
|
-
|
|
189
|
+
bb.on('field', function (fieldName, fieldVal) {
|
|
190
190
|
fieldsStr += encodeURIComponent(fieldName) + '=' + encodeURIComponent(fieldVal) + '&';
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
bb.on('finish', function () {
|
|
194
194
|
const tasks = [];
|
|
195
195
|
|
|
196
196
|
if (fieldsStr.endsWith('&')) {
|
|
@@ -232,7 +232,7 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
|
232
232
|
|
|
233
233
|
stream.push(req.rawBody);
|
|
234
234
|
stream.push(null);
|
|
235
|
-
stream.pipe(
|
|
235
|
+
stream.pipe(bb);
|
|
236
236
|
} else {
|
|
237
237
|
const readStream = that.fs.createReadStream(req.rawBodyPath);
|
|
238
238
|
|
|
@@ -240,7 +240,7 @@ ReqParser.prototype.parseFormMultipart = function parseFormMultipart(req, cb) {
|
|
|
240
240
|
that.log.error(logPrefix + 'Can not create read stream to file. Path: "' + req.rawBodyPath + '", err: ' + err.message);
|
|
241
241
|
});
|
|
242
242
|
|
|
243
|
-
readStream.pipe(
|
|
243
|
+
readStream.pipe(bb);
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
246
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "larvitreqparser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Middleware to larvitbase or Express to handle forms",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "eslint ./",
|
|
8
|
-
"test": "npm run lint && nyc --reporter=lcov tape test/**/*.js
|
|
8
|
+
"test": "npm run lint && nyc --reporter=lcov tape test/**/*.js"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -27,19 +27,18 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/larvit/larvitreqparser#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"
|
|
31
|
-
"eslint": "
|
|
30
|
+
"axios": "0.26.1",
|
|
31
|
+
"eslint": "8.13.0",
|
|
32
|
+
"form-data": "4.0.0",
|
|
32
33
|
"nyc": "15.1.0",
|
|
33
|
-
"
|
|
34
|
-
"tap-spec": "5.0.0",
|
|
35
|
-
"tape": "4.13.3"
|
|
34
|
+
"tape": "5.5.3"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"async": "3.2.
|
|
39
|
-
"busboy": "
|
|
40
|
-
"fs-extra": "
|
|
41
|
-
"larvitutils": "
|
|
42
|
-
"qs": "6.
|
|
43
|
-
"uuid": "
|
|
37
|
+
"async": "3.2.3",
|
|
38
|
+
"busboy": "1.5.0",
|
|
39
|
+
"fs-extra": "10.1.0",
|
|
40
|
+
"larvitutils": "5.0.5",
|
|
41
|
+
"qs": "6.10.3",
|
|
42
|
+
"uuid": "8.3.2"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/renovate.json
CHANGED
package/test/test.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ReqParser = require(__dirname + '/../index.js');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const FormData = require('form-data');
|
|
5
|
+
const { Log } = require('larvitutils');
|
|
6
|
+
const uuidLib = require('uuid');
|
|
6
7
|
const tmpDir = require('os').tmpdir();
|
|
7
|
-
const
|
|
8
|
+
const axios = require('axios').default;
|
|
8
9
|
const test = require('tape');
|
|
9
10
|
const http = require('http');
|
|
10
|
-
const log = new LUtils.Log('none');
|
|
11
11
|
const fs = require('fs-extra');
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
const log = new Log('none');
|
|
15
|
+
|
|
13
16
|
/* eslint-disable require-jsdoc */
|
|
14
17
|
|
|
15
18
|
function startServer(reqParser, reqHandler, cb) {
|
|
@@ -50,7 +53,7 @@ test('GET Http request, no body, no passed log instance', t => {
|
|
|
50
53
|
if (err) throw err;
|
|
51
54
|
server = result;
|
|
52
55
|
port = server.address().port;
|
|
53
|
-
|
|
56
|
+
axios('http://127.0.0.1:' + port + '/foo?bar=baz');
|
|
54
57
|
});
|
|
55
58
|
});
|
|
56
59
|
|
|
@@ -125,15 +128,15 @@ test('POST, raw body, memory storage', t => {
|
|
|
125
128
|
if (err) throw err;
|
|
126
129
|
server = result;
|
|
127
130
|
port = server.address().port;
|
|
128
|
-
|
|
131
|
+
axios({
|
|
129
132
|
url: 'http://127.0.0.1:' + port + '/',
|
|
130
|
-
|
|
133
|
+
data: 'foobar',
|
|
131
134
|
});
|
|
132
135
|
});
|
|
133
136
|
});
|
|
134
137
|
|
|
135
138
|
test('POST, raw body, fs storage', t => {
|
|
136
|
-
const storagePath = tmpDir + '/' +
|
|
139
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
137
140
|
const reqParser = new ReqParser({ storage: storagePath, log });
|
|
138
141
|
|
|
139
142
|
let server;
|
|
@@ -159,15 +162,16 @@ test('POST, raw body, fs storage', t => {
|
|
|
159
162
|
if (err) throw err;
|
|
160
163
|
server = result;
|
|
161
164
|
port = server.address().port;
|
|
162
|
-
|
|
165
|
+
axios({
|
|
166
|
+
method: 'POST',
|
|
163
167
|
url: 'http://127.0.0.1:' + port + '/',
|
|
164
|
-
|
|
168
|
+
data: 'foobar',
|
|
165
169
|
});
|
|
166
170
|
});
|
|
167
171
|
});
|
|
168
172
|
|
|
169
173
|
test('POST, raw body, custom fs storage and busboy options', t => {
|
|
170
|
-
const storagePath = tmpDir + '/' +
|
|
174
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
171
175
|
const reqParser = new ReqParser({
|
|
172
176
|
storage: storagePath,
|
|
173
177
|
log,
|
|
@@ -198,9 +202,10 @@ test('POST, raw body, custom fs storage and busboy options', t => {
|
|
|
198
202
|
if (err) throw err;
|
|
199
203
|
server = result;
|
|
200
204
|
port = server.address().port;
|
|
201
|
-
|
|
205
|
+
axios({
|
|
206
|
+
method: 'POST',
|
|
202
207
|
url: 'http://127.0.0.1:' + port + '/',
|
|
203
|
-
|
|
208
|
+
data: 'foobar',
|
|
204
209
|
});
|
|
205
210
|
});
|
|
206
211
|
});
|
|
@@ -226,9 +231,10 @@ test('POST, raw body, fs storage, invalid path', t => {
|
|
|
226
231
|
if (err) throw err;
|
|
227
232
|
server = result;
|
|
228
233
|
port = server.address().port;
|
|
229
|
-
|
|
234
|
+
axios({
|
|
235
|
+
method: 'POST',
|
|
230
236
|
url: 'http://127.0.0.1:' + port + '/',
|
|
231
|
-
|
|
237
|
+
data: 'foobar',
|
|
232
238
|
});
|
|
233
239
|
});
|
|
234
240
|
});
|
|
@@ -248,7 +254,7 @@ test('POST, application/x-www-form-urlencoded, memory storage', t => {
|
|
|
248
254
|
|
|
249
255
|
t.equal(
|
|
250
256
|
req.rawBody.toString(),
|
|
251
|
-
'foo=bar&beng
|
|
257
|
+
'foo=bar&beng+tops=arr&beng+tops=ay&beng+tops=%C3%B6ber+alles+%26+%C3%A4nnu+mer',
|
|
252
258
|
'rawBody should be the raw form content',
|
|
253
259
|
);
|
|
254
260
|
t.equal(
|
|
@@ -262,22 +268,17 @@ test('POST, application/x-www-form-urlencoded, memory storage', t => {
|
|
|
262
268
|
if (err) throw err;
|
|
263
269
|
server = result;
|
|
264
270
|
port = server.address().port;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
'ay',
|
|
272
|
-
'öber alles & ännu mer',
|
|
273
|
-
],
|
|
274
|
-
},
|
|
275
|
-
});
|
|
271
|
+
const formData = new URLSearchParams();
|
|
272
|
+
formData.append('foo', 'bar');
|
|
273
|
+
formData.append('beng tops', 'arr');
|
|
274
|
+
formData.append('beng tops', 'ay');
|
|
275
|
+
formData.append('beng tops', 'öber alles & ännu mer');
|
|
276
|
+
axios.post('http://127.0.0.1:' + port + '/', formData);
|
|
276
277
|
});
|
|
277
278
|
});
|
|
278
279
|
|
|
279
280
|
test('POST, application/x-www-form-urlencoded, fs storage', t => {
|
|
280
|
-
const storagePath = tmpDir + '/' +
|
|
281
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
281
282
|
const reqParser = new ReqParser({ storage: storagePath, log });
|
|
282
283
|
|
|
283
284
|
let server;
|
|
@@ -292,7 +293,7 @@ test('POST, application/x-www-form-urlencoded, fs storage', t => {
|
|
|
292
293
|
|
|
293
294
|
t.equal(
|
|
294
295
|
fs.readFileSync(req.rawBodyPath).toString(),
|
|
295
|
-
'foo=bar&beng
|
|
296
|
+
'foo=bar&beng+tops=arr&beng+tops=ay&beng+tops=%C3%B6ber+alles+%26+%C3%A4nnu+mer',
|
|
296
297
|
'rawBody should be the raw form content',
|
|
297
298
|
);
|
|
298
299
|
t.equal(
|
|
@@ -306,22 +307,17 @@ test('POST, application/x-www-form-urlencoded, fs storage', t => {
|
|
|
306
307
|
if (err) throw err;
|
|
307
308
|
server = result;
|
|
308
309
|
port = server.address().port;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
'ay',
|
|
316
|
-
'öber alles & ännu mer',
|
|
317
|
-
],
|
|
318
|
-
},
|
|
319
|
-
});
|
|
310
|
+
const formData = new URLSearchParams();
|
|
311
|
+
formData.append('foo', 'bar');
|
|
312
|
+
formData.append('beng tops', 'arr');
|
|
313
|
+
formData.append('beng tops', 'ay');
|
|
314
|
+
formData.append('beng tops', 'öber alles & ännu mer');
|
|
315
|
+
axios.post('http://127.0.0.1:' + port + '/', formData);
|
|
320
316
|
});
|
|
321
317
|
});
|
|
322
318
|
|
|
323
319
|
test('POST, application/x-www-form-urlencoded, fs storage parameterLimit: 6', t => {
|
|
324
|
-
const storagePath = tmpDir + '/' +
|
|
320
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
325
321
|
const reqParser = new ReqParser({ storage: storagePath, qsParseOptions: { parameterLimit: 6 }, log });
|
|
326
322
|
|
|
327
323
|
let server;
|
|
@@ -336,7 +332,7 @@ test('POST, application/x-www-form-urlencoded, fs storage parameterLimit: 6', t
|
|
|
336
332
|
|
|
337
333
|
t.equal(
|
|
338
334
|
fs.readFileSync(req.rawBodyPath).toString(),
|
|
339
|
-
'foo=bar&beng
|
|
335
|
+
'foo=bar&beng+tops=arr&beng+tops=ay&beng+tops=%C3%B6ber+alles+%26+%C3%A4nnu+mer&testar=jaha&testar=nehe&testar=ojd%C3%A5',
|
|
340
336
|
'rawBody should be the raw form content',
|
|
341
337
|
);
|
|
342
338
|
t.equal(
|
|
@@ -350,22 +346,15 @@ test('POST, application/x-www-form-urlencoded, fs storage parameterLimit: 6', t
|
|
|
350
346
|
if (err) throw err;
|
|
351
347
|
server = result;
|
|
352
348
|
port = server.address().port;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
testar: [
|
|
363
|
-
'jaha',
|
|
364
|
-
'nehe',
|
|
365
|
-
'ojdå',
|
|
366
|
-
],
|
|
367
|
-
},
|
|
368
|
-
});
|
|
349
|
+
const formData = new URLSearchParams();
|
|
350
|
+
formData.append('foo', 'bar');
|
|
351
|
+
formData.append('beng tops', 'arr');
|
|
352
|
+
formData.append('beng tops', 'ay');
|
|
353
|
+
formData.append('beng tops', 'öber alles & ännu mer');
|
|
354
|
+
formData.append('testar', 'jaha');
|
|
355
|
+
formData.append('testar', 'nehe');
|
|
356
|
+
formData.append('testar', 'ojdå');
|
|
357
|
+
axios.post('http://127.0.0.1:' + port + '/', formData);
|
|
369
358
|
});
|
|
370
359
|
});
|
|
371
360
|
|
|
@@ -396,41 +385,32 @@ test('POST, multipart/form-data, memory storage', t => {
|
|
|
396
385
|
|
|
397
386
|
t.end();
|
|
398
387
|
}, (err, result) => {
|
|
399
|
-
const formData = {};
|
|
400
|
-
|
|
401
388
|
if (err) throw err;
|
|
402
389
|
|
|
403
390
|
server = result;
|
|
404
391
|
port = server.address().port;
|
|
405
392
|
|
|
406
|
-
formData
|
|
407
|
-
formData
|
|
408
|
-
formData['
|
|
409
|
-
formData
|
|
410
|
-
formData
|
|
411
|
-
formData
|
|
412
|
-
formData.
|
|
413
|
-
formData
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
options: {
|
|
420
|
-
filename: 'reven.txt',
|
|
421
|
-
contentType: 'text/plain',
|
|
422
|
-
},
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
request({
|
|
426
|
-
url: 'http://127.0.0.1:' + port + '/',
|
|
427
|
-
formData: formData,
|
|
393
|
+
const formData = new FormData();
|
|
394
|
+
formData.append('foo', 'bar');
|
|
395
|
+
formData.append('ove[]', 'första ove');
|
|
396
|
+
formData.append('beng tops', 'öber alles & ännu mer');
|
|
397
|
+
formData.append('untz[firstname]', 'kalle');
|
|
398
|
+
formData.append('untz[lastname][first]', 'benktsson');
|
|
399
|
+
formData.append('untz[lastname][second]', 'lurresson');
|
|
400
|
+
formData.append('enLitenBuffer', Buffer.from('foo feng fall'));
|
|
401
|
+
formData.append('arrWithBuffers[]', Buffer.from('apa'));
|
|
402
|
+
formData.append('arrWithBuffers[]', Buffer.from('bengbison'));
|
|
403
|
+
formData.append('customFile', Buffer.from('skruppelräv'), {
|
|
404
|
+
filename: 'reven.txt',
|
|
405
|
+
contentType: 'text/plain',
|
|
428
406
|
});
|
|
407
|
+
|
|
408
|
+
axios.post('http://127.0.0.1:' + port + '/', formData, { headers: formData.getHeaders() });
|
|
429
409
|
});
|
|
430
410
|
});
|
|
431
411
|
|
|
432
412
|
test('POST, multipart/form-data, fs storage', t => {
|
|
433
|
-
const storagePath = tmpDir + '/' +
|
|
413
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
434
414
|
const reqParser = new ReqParser({ storage: storagePath, log });
|
|
435
415
|
|
|
436
416
|
let server;
|
|
@@ -466,33 +446,24 @@ test('POST, multipart/form-data, fs storage', t => {
|
|
|
466
446
|
}, 50);
|
|
467
447
|
});
|
|
468
448
|
}, (err, result) => {
|
|
469
|
-
const formData = {};
|
|
470
|
-
|
|
471
449
|
if (err) throw err;
|
|
472
450
|
|
|
473
451
|
server = result;
|
|
474
452
|
port = server.address().port;
|
|
475
453
|
|
|
476
|
-
formData
|
|
477
|
-
formData
|
|
478
|
-
formData['
|
|
479
|
-
formData.
|
|
480
|
-
formData
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
options: {
|
|
487
|
-
filename: 'reven.txt',
|
|
488
|
-
contentType: 'text/plain',
|
|
489
|
-
},
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
request({
|
|
493
|
-
url: 'http://127.0.0.1:' + port + '/',
|
|
494
|
-
formData: formData,
|
|
454
|
+
const formData = new FormData();
|
|
455
|
+
formData.append('foo', 'bar');
|
|
456
|
+
formData.append('ove[]', 'första ove');
|
|
457
|
+
formData.append('beng tops', 'öber alles & ännu mer');
|
|
458
|
+
formData.append('enLitenBuffer', Buffer.from('foo feng fall'));
|
|
459
|
+
formData.append('arrWithBuffers[]', Buffer.from('apa'));
|
|
460
|
+
formData.append('arrWithBuffers[]', Buffer.from('bengbison'));
|
|
461
|
+
formData.append('customFile', Buffer.from('skruppelräv'), {
|
|
462
|
+
filename: 'reven.txt',
|
|
463
|
+
contentType: 'text/plain',
|
|
495
464
|
});
|
|
465
|
+
|
|
466
|
+
axios.post('http://127.0.0.1:' + port + '/', formData, { headers: formData.getHeaders() });
|
|
496
467
|
});
|
|
497
468
|
});
|
|
498
469
|
|
|
@@ -517,18 +488,19 @@ test('POST, empty form should not crasch application', t => {
|
|
|
517
488
|
server = result;
|
|
518
489
|
port = server.address().port;
|
|
519
490
|
|
|
520
|
-
|
|
491
|
+
axios({
|
|
492
|
+
method: 'POST',
|
|
521
493
|
url: 'http://127.0.0.1:' + port + '/',
|
|
494
|
+
data: undefined,
|
|
522
495
|
headers: {
|
|
523
496
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
524
497
|
},
|
|
525
|
-
body: undefined,
|
|
526
498
|
});
|
|
527
499
|
});
|
|
528
500
|
});
|
|
529
501
|
|
|
530
502
|
test('clean will remove temporary form files', t => {
|
|
531
|
-
const storagePath = tmpDir + '/' +
|
|
503
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
532
504
|
const reqParser = new ReqParser({ storage: storagePath, log });
|
|
533
505
|
|
|
534
506
|
let server;
|
|
@@ -561,43 +533,30 @@ test('clean will remove temporary form files', t => {
|
|
|
561
533
|
}, 50);
|
|
562
534
|
});
|
|
563
535
|
}, (err, result) => {
|
|
564
|
-
const formData = {};
|
|
565
|
-
|
|
566
536
|
if (err) throw err;
|
|
567
537
|
|
|
568
538
|
server = result;
|
|
569
539
|
port = server.address().port;
|
|
570
540
|
|
|
571
|
-
formData
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
value: Buffer.from('nissepisse'),
|
|
581
|
-
options: {
|
|
582
|
-
filename: 'nisse.txt',
|
|
583
|
-
contentType: 'text/plain',
|
|
584
|
-
},
|
|
585
|
-
};
|
|
541
|
+
const formData = new FormData();
|
|
542
|
+
formData.append('customFile', Buffer.from('skruppelräv'), {
|
|
543
|
+
filename: 'reven.txt',
|
|
544
|
+
contentType: 'text/plain',
|
|
545
|
+
});
|
|
546
|
+
formData.append('manuallyCleanedUp', Buffer.from('nissepisse'), {
|
|
547
|
+
filename: 'nisse.txt',
|
|
548
|
+
contentType: 'text/plain',
|
|
549
|
+
});
|
|
586
550
|
|
|
587
|
-
formData
|
|
588
|
-
|
|
589
|
-
Buffer.from('bengbison'),
|
|
590
|
-
];
|
|
551
|
+
formData.append('arrWithBuffers[]', Buffer.from('apa'));
|
|
552
|
+
formData.append('arrWithBuffers[]', Buffer.from('bengbison'));
|
|
591
553
|
|
|
592
|
-
|
|
593
|
-
url: 'http://127.0.0.1:' + port + '/',
|
|
594
|
-
formData: formData,
|
|
595
|
-
});
|
|
554
|
+
axios.post('http://127.0.0.1:' + port + '/', formData, { headers: formData.getHeaders() });
|
|
596
555
|
});
|
|
597
556
|
});
|
|
598
557
|
|
|
599
558
|
test('clean will remove temporary raw body file', t => {
|
|
600
|
-
const storagePath = tmpDir + '/' +
|
|
559
|
+
const storagePath = tmpDir + '/' + uuidLib.v4();
|
|
601
560
|
const reqParser = new ReqParser({ storage: storagePath, log });
|
|
602
561
|
|
|
603
562
|
let server;
|
|
@@ -630,7 +589,7 @@ test('clean will remove temporary raw body file', t => {
|
|
|
630
589
|
|
|
631
590
|
formData.foo = 'bar';
|
|
632
591
|
|
|
633
|
-
|
|
592
|
+
axios({
|
|
634
593
|
url: 'http://127.0.0.1:' + port + '/',
|
|
635
594
|
formData: formData,
|
|
636
595
|
});
|