Skip to content

Commit

Permalink
added SSL info when create agent
Browse files Browse the repository at this point in the history
  • Loading branch information
tom zhou committed Nov 24, 2013
1 parent 0b2581e commit abf9ccf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 45 deletions.
14 changes: 12 additions & 2 deletions lib/node-http-proxy.js
Expand Up @@ -375,6 +375,16 @@ exports._getAgent = function _getAgent (options) {
// require('http-proxy').setMaxSockets() should override http's default
// configuration value (which is pretty low).
options.maxSockets = options.maxSockets || maxSockets;

// set SSL related info
if (options.https && typeof options.https === 'object') {
['pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers', 'rejectUnauthorized'].forEach(function (key) {
if (options.https[key]) {
options[key] = options.https[key];
}
});
}

agent = new Agent(options);

return agent;
Expand All @@ -396,13 +406,13 @@ exports._getProtocol = function _getProtocol (options) {
// #### @options {Object} Options for the proxy target.
// Returns the relevate base object to create on outgoing proxy request.
// If `options.https` are supplied, this function respond with an object
// containing the relevant `ca`, `key`, and `cert` properties.
// containing the relevant 'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers', and 'rejectUnauthorized' properties.
//
exports._getBase = function _getBase (options) {
var result = function () {};

if (options.https && typeof options.https === 'object') {
['ca', 'cert', 'key'].forEach(function (key) {
['pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers', 'rejectUnauthorized'].forEach(function (key) {
if (options.https[key]) {
result.prototype[key] = options.https[key];
}
Expand Down
44 changes: 1 addition & 43 deletions lib/node-http-proxy/http-proxy.js
Expand Up @@ -249,21 +249,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
// Setup custom createConnection
//
outgoing.createConnection = this.target.createConnection;

//
// Setup SSL related info
//
var tmphttps = this.target.https;
if (typeof tmphttps === 'object') {
var sslkeys = {pfx: '', key: '', passphrase: '', cert: '', ca: '', ciphers: '', rejectUnauthorized: ''};

Object.keys(tmphttps).forEach(function(k){
if (k in sslkeys) {
outgoing[k] = tmphttps[k];
}
});
}

// cache origin req.host
this.oriReqHost = req.headers.host;

Expand Down Expand Up @@ -809,21 +795,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, upgradeHead,
// Setup custom createConnection
//
outgoing.createConnection = this.target.createConnection;

//
// Setup SSL related info
//
var tmphttps = this.target.https;
if (typeof tmphttps === 'object') {
var sslkeys = {pfx: '', key: '', passphrase: '', cert: '', ca: '', ciphers: '', rejectUnauthorized: ''};

Object.keys(tmphttps).forEach(function(k){
if (k in sslkeys) {
outgoing[k] = tmphttps[k];
}
});
}

var reverseProxy = this.target.protocol.request(outgoing);

//
Expand Down Expand Up @@ -1094,21 +1066,7 @@ HttpProxy.prototype._forwardRequest = function (req) {
// Setup custom createConnection
//
outgoing.createConnection = this.forward.createConnection;

//
// Setup SSL related info
//
var tmphttps = this.forward.https;
if (typeof tmphttps === 'object') {
var sslkeys = {pfx: '', key: '', passphrase: '', cert: '', ca: '', ciphers: '', rejectUnauthorized: ''};

Object.keys(tmphttps).forEach(function(k){
if (k in sslkeys) {
outgoing[k] = tmphttps[k];
}
});
}


//
// Open new HTTP request to internal resource with will
// act as a reverse proxy pass.
Expand Down

0 comments on commit abf9ccf

Please sign in to comment.