Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,20 @@ common.getPort = function(req) {

return res ?
res[1] :
req.connection.pair ? '443' : '80';
common.hasEncryptedConnection(req) ? '443' : '80';
};

/**
* Check if the request has an encrypted connection.
*
* @param {Request} req Incoming HTTP request.
*
* @return {Boolean} Whether the connection is encrypted or not.
*
* @api private
*/
common.hasEncryptedConnection = function(req) {
return Boolean(req.connection.encrypted || req.connection.pair);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ web_o = Object.keys(web_o).map(function(pass) {
function XHeaders(req, res, options) {
if(!options.xfwd) return;

var encrypted = req.isSpdy || req.connection.encrypted || req.connection.pair;
var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
var values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
Expand Down
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var passes = exports;
var values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
proto: req.connection.pair ? 'wss' : 'ws'
proto: common.hasEncryptedConnection(req) ? 'wss' : 'ws'
};

['for', 'port', 'proto'].forEach(function(header) {
Expand Down
12 changes: 11 additions & 1 deletion test/lib-https-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('lib/http-proxy.js', function() {
ssl: {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
}
}).listen(ports.proxy);

Expand Down Expand Up @@ -65,6 +66,7 @@ describe('lib/http-proxy.js', function() {
var source = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
}, function (req, res) {
expect(req.method).to.eql('GET');
expect(req.headers.host.split(':')[1]).to.eql(ports.proxy);
Expand Down Expand Up @@ -105,6 +107,7 @@ describe('lib/http-proxy.js', function() {
var source = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
}, function(req, res) {
expect(req.method).to.eql('GET');
expect(req.headers.host.split(':')[1]).to.eql(ports.proxy);
Expand All @@ -119,6 +122,7 @@ describe('lib/http-proxy.js', function() {
ssl: {
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
},
secure: false
}).listen(ports.proxy);
Expand Down Expand Up @@ -150,6 +154,7 @@ describe('lib/http-proxy.js', function() {
var source = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
}).listen(ports.source);

var proxy = httpProxy.createProxyServer({
Expand All @@ -161,7 +166,11 @@ describe('lib/http-proxy.js', function() {

proxy.on('error', function (err, req, res) {
expect(err).to.be.an(Error);
expect(err.toString()).to.be('Error: DEPTH_ZERO_SELF_SIGNED_CERT')
if (process.versions.node.indexOf('0.12.') == 0) {
expect(err.toString()).to.be('Error: self signed certificate')
} else {
expect(err.toString()).to.be('Error: DEPTH_ZERO_SELF_SIGNED_CERT')
}
done();
})

Expand Down Expand Up @@ -191,6 +200,7 @@ describe('lib/http-proxy.js', function() {
var ownServer = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
ciphers: 'AES128-GCM-SHA256',
}, function (req, res) {
proxy.web(req, res, {
target: 'http://127.0.0.1:' + ports.source
Expand Down