2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-30 18:38:06 -05:00
|
|
|
const common = require('../common');
|
2017-10-06 17:52:28 +00:00
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
|
|
2017-07-01 02:29:09 +03:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip('missing crypto');
|
2015-03-05 09:36:47 +11:00
|
|
|
|
2017-07-01 02:29:09 +03:00
|
|
|
const assert = require('assert');
|
|
|
|
|
const https = require('https');
|
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const options = {
|
2017-10-06 17:52:28 +00:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2016-01-13 21:42:45 +01:00
|
|
|
};
|
|
|
|
|
const httpsServer = https.createServer(options, reqHandler);
|
2015-03-05 09:36:47 +11:00
|
|
|
|
|
|
|
|
function reqHandler(req, res) {
|
2017-04-28 04:06:42 +03:00
|
|
|
console.log(`Got request: ${req.headers.host} ${req.url}`);
|
2015-03-05 09:36:47 +11:00
|
|
|
if (req.url === '/setHostFalse5') {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(req.headers.host, undefined);
|
2015-03-05 09:36:47 +11:00
|
|
|
} else {
|
2017-04-28 04:06:42 +03:00
|
|
|
assert.strictEqual(
|
|
|
|
|
req.headers.host, `localhost:${this.address().port}`,
|
|
|
|
|
`Wrong host header for req[${req.url}]: ${req.headers.host}`);
|
2015-03-05 09:36:47 +11:00
|
|
|
}
|
|
|
|
|
res.writeHead(200, {});
|
|
|
|
|
res.end('ok');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function thrower(er) {
|
|
|
|
|
throw er;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testHttps();
|
|
|
|
|
|
|
|
|
|
function testHttps() {
|
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let counter = 0;
|
2015-03-05 09:36:47 +11:00
|
|
|
|
|
|
|
|
function cb(res) {
|
|
|
|
|
counter--;
|
2017-04-28 04:06:42 +03:00
|
|
|
console.log(`back from https request. counter = ${counter}`);
|
2015-03-05 09:36:47 +11:00
|
|
|
if (counter === 0) {
|
|
|
|
|
httpsServer.close();
|
|
|
|
|
console.log('ok');
|
|
|
|
|
}
|
|
|
|
|
res.resume();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
httpsServer.listen(0, function(er) {
|
|
|
|
|
console.log(`test https server listening on port ${this.address().port}`);
|
2016-12-30 10:54:01 -05:00
|
|
|
assert.ifError(er);
|
2015-03-05 09:36:47 +11:00
|
|
|
https.get({
|
|
|
|
|
method: 'GET',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower);
|
|
|
|
|
|
|
|
|
|
https.request({
|
|
|
|
|
method: 'GET',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower).end();
|
|
|
|
|
|
|
|
|
|
https.request({
|
|
|
|
|
method: 'POST',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower).end();
|
|
|
|
|
|
|
|
|
|
https.request({
|
|
|
|
|
method: 'PUT',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower).end();
|
|
|
|
|
|
|
|
|
|
https.request({
|
|
|
|
|
method: 'DELETE',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower).end();
|
|
|
|
|
|
|
|
|
|
https.get({
|
|
|
|
|
method: 'GET',
|
2017-04-28 04:06:42 +03:00
|
|
|
path: `/setHostFalse${counter++}`,
|
2015-03-05 09:36:47 +11:00
|
|
|
host: 'localhost',
|
|
|
|
|
setHost: false,
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2015-03-05 09:36:47 +11:00
|
|
|
rejectUnauthorized: false
|
|
|
|
|
}, cb).on('error', thrower).end();
|
|
|
|
|
});
|
|
|
|
|
}
|