-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
tester.js
52 lines (42 loc) · 1 KB
/
tester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict'
const http = require('node:http')
const Readable = require('node:stream').Readable
const FormData = require('form-data')
const pump = require('pump')
const knownLength = 1024 * 1024 * 1024
function next () {
let total = knownLength
const form = new FormData({ maxDataSize: total })
const rs = new Readable({
read (n) {
if (n > total) {
n = total
}
// poor man random data
// do not use in prod, it can leak sensitive informations
const buf = Buffer.allocUnsafe(n)
this.push(buf)
total -= n
if (total === 0) {
this.push(null)
}
}
})
form.append('my_field', 'my value')
form.append('upload', rs, {
filename: 'random-data',
contentType: 'binary/octet-stream',
knownLength
})
const opts = {
protocol: 'http:',
hostname: 'localhost',
port: 3000,
path: '/upload',
headers: form.getHeaders(),
method: 'POST'
}
const req = http.request(opts, next)
pump(form, req)
}
next()