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-01-13 21:42:45 +01:00
|
|
|
const common = require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
|
|
|
common.skip('missing crypto');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const http = require('http');
|
2016-12-31 00:38:06 +01:00
|
|
|
const https = require('https');
|
2016-01-13 21:42:45 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const hostExpect = 'localhost';
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2016-05-26 18:43:09 +02:00
|
|
|
const fixtures = path.join(common.fixturesDir, 'keys');
|
2016-01-13 21:42:45 +01:00
|
|
|
const options = {
|
|
|
|
key: fs.readFileSync(fixtures + '/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(fixtures + '/agent1-cert.pem')
|
|
|
|
};
|
|
|
|
let gotHttpsResp = false;
|
|
|
|
let gotHttpResp = false;
|
2013-08-04 08:39:50 +02:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2015-03-04 02:11:21 +01:00
|
|
|
if (common.hasCrypto) {
|
|
|
|
assert(gotHttpsResp);
|
|
|
|
}
|
2013-08-04 08:39:50 +02:00
|
|
|
assert(gotHttpResp);
|
|
|
|
console.log('ok');
|
|
|
|
});
|
|
|
|
|
2011-10-05 00:08:18 +02:00
|
|
|
http.createServer(function(req, res) {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(req.headers.host, hostExpect);
|
|
|
|
assert.strictEqual(req.headers['x-port'], this.address().port.toString());
|
2011-08-08 02:36:49 +02:00
|
|
|
res.writeHead(200);
|
2011-10-05 00:08:18 +02:00
|
|
|
res.end('ok');
|
2011-08-08 02:36:49 +02:00
|
|
|
this.close();
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(0, function() {
|
|
|
|
http.globalAgent.defaultPort = this.address().port;
|
2013-08-04 08:39:50 +02:00
|
|
|
http.get({
|
|
|
|
host: 'localhost',
|
|
|
|
headers: {
|
2016-05-29 09:06:56 +02:00
|
|
|
'x-port': this.address().port
|
2013-08-04 08:39:50 +02:00
|
|
|
}
|
|
|
|
}, function(res) {
|
|
|
|
gotHttpResp = true;
|
|
|
|
res.resume();
|
|
|
|
});
|
|
|
|
});
|
2011-08-08 02:36:49 +02:00
|
|
|
|
2015-03-04 02:11:21 +01:00
|
|
|
if (common.hasCrypto) {
|
|
|
|
https.createServer(options, function(req, res) {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(req.headers.host, hostExpect);
|
|
|
|
assert.strictEqual(req.headers['x-port'], this.address().port.toString());
|
2015-03-04 02:11:21 +01:00
|
|
|
res.writeHead(200);
|
|
|
|
res.end('ok');
|
|
|
|
this.close();
|
2016-05-29 09:06:56 +02:00
|
|
|
}).listen(0, function() {
|
|
|
|
https.globalAgent.defaultPort = this.address().port;
|
2015-12-26 00:32:13 +01:00
|
|
|
https.get({
|
2015-03-04 02:11:21 +01:00
|
|
|
host: 'localhost',
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
headers: {
|
2016-05-29 09:06:56 +02:00
|
|
|
'x-port': this.address().port
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|
|
|
|
}, function(res) {
|
|
|
|
gotHttpsResp = true;
|
|
|
|
res.resume();
|
|
|
|
});
|
2013-08-04 08:39:50 +02:00
|
|
|
});
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|