test-delayed-http-upload.js
828 Bytes
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
var common = require('../common');
var assert = common.assert;
var DelayedStream = common.DelayedStream;
var http = require('http');
var UPLOAD = new Buffer(10 * 1024 * 1024);
var server = http.createServer(function(req, res) {
var delayed = DelayedStream.create(req, {maxDataSize: UPLOAD.length});
setTimeout(function() {
res.writeHead(200);
delayed.pipe(res);
}, 10);
});
server.listen(common.PORT, function() {
var request = http.request({
method: 'POST',
port: common.PORT,
});
request.write(UPLOAD);
request.end();
request.on('response', function(res) {
var received = 0;
res
.on('data', function(chunk) {
received += chunk.length;
})
.on('end', function() {
assert.equal(received, UPLOAD.length);
server.close();
});
});
});