2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2011-01-28 04:27:25 +01:00
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const fs = require('fs');
|
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
|
|
|
}
|
2016-12-31 00:38:06 +01:00
|
|
|
const https = require('https');
|
2011-01-28 04:27:25 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const options = {
|
2011-01-28 04:27:25 +01:00
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
|
|
};
|
|
|
|
|
|
|
|
process.stdout.write('build body...');
|
2017-01-08 14:19:00 +01:00
|
|
|
const body = 'hello world\n'.repeat(1024 * 1024);
|
2011-01-28 04:27:25 +01:00
|
|
|
process.stdout.write('done\n');
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = https.createServer(options, common.mustCall(function(req, res) {
|
2011-01-28 04:27:25 +01:00
|
|
|
console.log('got request');
|
|
|
|
res.writeHead(200, { 'content-type': 'text/plain' });
|
|
|
|
res.end(body);
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
2011-01-28 04:27:25 +01:00
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
server.listen(common.PORT, common.mustCall(function() {
|
2012-08-30 16:43:20 +02:00
|
|
|
https.get({
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: false
|
2016-07-15 21:43:24 +02:00
|
|
|
}, common.mustCall(function(res) {
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('response!');
|
2011-01-28 04:27:25 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let count = 0;
|
2016-07-15 21:43:24 +02:00
|
|
|
|
2011-01-28 04:27:25 +01:00
|
|
|
res.on('data', function(d) {
|
|
|
|
process.stdout.write('.');
|
|
|
|
count += d.length;
|
2011-01-28 08:37:53 +01:00
|
|
|
res.pause();
|
2011-10-05 00:08:18 +02:00
|
|
|
process.nextTick(function() {
|
2011-01-28 08:37:53 +01:00
|
|
|
res.resume();
|
|
|
|
});
|
2011-01-28 04:27:25 +01:00
|
|
|
});
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
res.on('end', common.mustCall(function(d) {
|
2011-01-28 04:27:25 +01:00
|
|
|
process.stdout.write('\n');
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('expected: ', body.length);
|
|
|
|
console.log(' got: ', count);
|
2011-01-28 04:27:25 +01:00
|
|
|
server.close();
|
2016-07-15 21:43:24 +02:00
|
|
|
assert.strictEqual(count, body.length);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|