@@ -113,8 +113,7 @@ exports.setMaxSockets = function (value) {
113
113
exports . createServer = function ( ) {
114
114
var args = Array . prototype . slice . call ( arguments ) ,
115
115
callback = typeof args [ 0 ] === 'function' && args . shift ( ) ,
116
- options = { } ,
117
- port , host , forward , silent , proxy , server ;
116
+ options = { } , port , host , forward , silent , proxy , server ;
118
117
119
118
if ( args . length >= 2 ) {
120
119
port = args [ 0 ] ;
@@ -221,8 +220,10 @@ var HttpProxy = exports.HttpProxy = function (options) {
221
220
222
221
var self = this ;
223
222
options = options || { } ;
223
+ options . target = options . target || { } ;
224
+
224
225
this . forward = options . forward ;
225
- this . https = options . https ;
226
+ this . target = options . target ;
226
227
this . changeOrigin = options . changeOrigin || false ;
227
228
228
229
if ( options . router ) {
@@ -303,8 +304,14 @@ HttpProxy.prototype.close = function () {
303
304
HttpProxy . prototype . proxyRequest = function ( req , res , options ) {
304
305
var self = this , errState = false , location , outgoing , protocol , reverseProxy ;
305
306
307
+ //
306
308
// Create an empty options hash if none is passed.
307
- options = options || { } ;
309
+ // If default options have been passed to the constructor
310
+ // of this instance, use them by default.
311
+ //
312
+ options = options || { } ;
313
+ options . host = options . host || this . target . host ;
314
+ options . port = options . port || this . target . port ;
308
315
309
316
//
310
317
// Check the proxy table for this instance to see if we need
@@ -375,7 +382,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
375
382
outgoing = {
376
383
host : options . host ,
377
384
port : options . port ,
378
- agent : _getAgent ( options . host , options . port , options . https || this . https ) ,
385
+ agent : _getAgent ( options . host , options . port , options . https || this . target . https ) ,
379
386
method : req . method ,
380
387
path : req . url ,
381
388
headers : req . headers
@@ -385,7 +392,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
385
392
// node.js core re-implements 'keep-alive'.
386
393
outgoing . headers [ 'connection' ] = 'close' ;
387
394
388
- protocol = _getProtocol ( options . https || this . https , outgoing ) ;
395
+ protocol = _getProtocol ( options . https || this . target . https , outgoing ) ;
389
396
390
397
// Open new HTTP request to internal resource with will act as a reverse proxy pass
391
398
reverseProxy = protocol . request ( outgoing , function ( response ) {
@@ -594,8 +601,8 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
594
601
_socket ( socket ) ;
595
602
596
603
// Remote host address
597
- var protocolName = options . https || this . https ? 'https' : 'http' ,
598
- agent = _getAgent ( options . host , options . port , options . https || this . https ) ,
604
+ var protocolName = options . https || this . target . https ? 'https' : 'http' ,
605
+ agent = _getAgent ( options . host , options . port , options . https || this . target . https ) ,
599
606
remoteHost = options . host + ( options . port - 80 === 0 ? '' : ':' + options . port ) ;
600
607
601
608
// Change headers
0 commit comments