2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-11-26 16:43:57 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|
2011-11-26 16:43:57 +01:00
|
|
|
var https = require('https');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2011-11-26 16:43:57 +01:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
|
|
|
|
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
|
|
|
|
};
|
|
|
|
|
|
|
|
var bufSize = 1024 * 1024;
|
|
|
|
var sent = 0;
|
|
|
|
var received = 0;
|
|
|
|
|
|
|
|
var server = https.createServer(options, function(req, res) {
|
|
|
|
res.writeHead(200);
|
|
|
|
req.pipe(res);
|
|
|
|
});
|
|
|
|
|
2016-05-29 09:06:56 +02:00
|
|
|
server.listen(0, function() {
|
2011-11-26 16:43:57 +01:00
|
|
|
var resumed = false;
|
|
|
|
var req = https.request({
|
2012-08-30 16:43:20 +02:00
|
|
|
method: 'POST',
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port,
|
2012-08-30 16:43:20 +02:00
|
|
|
rejectUnauthorized: false
|
2011-11-26 16:43:57 +01:00
|
|
|
}, function(res) {
|
|
|
|
var timer;
|
|
|
|
res.pause();
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('paused');
|
2011-11-26 16:43:57 +01:00
|
|
|
send();
|
|
|
|
function send() {
|
2016-01-26 00:00:06 +01:00
|
|
|
if (req.write(Buffer.allocUnsafe(bufSize))) {
|
2011-11-26 16:43:57 +01:00
|
|
|
sent += bufSize;
|
|
|
|
assert.ok(sent < 100 * 1024 * 1024); // max 100MB
|
|
|
|
return process.nextTick(send);
|
|
|
|
}
|
|
|
|
sent += bufSize;
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('sent: ' + sent);
|
2011-11-26 16:43:57 +01:00
|
|
|
resumed = true;
|
|
|
|
res.resume();
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('resumed');
|
2011-11-26 16:43:57 +01:00
|
|
|
timer = setTimeout(function() {
|
|
|
|
process.exit(1);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.on('data', function(data) {
|
|
|
|
assert.ok(resumed);
|
|
|
|
if (timer) {
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = null;
|
|
|
|
}
|
|
|
|
received += data.length;
|
|
|
|
if (received >= sent) {
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('received: ' + received);
|
2011-11-26 16:43:57 +01:00
|
|
|
req.end();
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
req.write('a');
|
|
|
|
++sent;
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(sent, received);
|
|
|
|
});
|