Skip to content

Commit

Permalink
fix tests for maintaining proxy path
Browse files Browse the repository at this point in the history
  • Loading branch information
EndangeredMassa committed Sep 8, 2014
1 parent 511b7b3 commit a65021d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/http-proxy/common.js
@@ -1,4 +1,5 @@
var common = exports,
path = require('path'),
url = require('url'),
extend = require('util')._extend;

Expand Down Expand Up @@ -57,17 +58,22 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
) { outgoing.headers.connection = 'close'; }
}


// the final path is target path + relative path requested by user:
outgoing.path = options.target.path;
var target = options[forward || 'target'];
var targetPath = target
? (target.path || '')
: '';

//
// Remark: Can we somehow not use url.parse as a perf optimization?
//
outgoing.path += !options.toProxy
var outgoingPath = !options.toProxy
? url.parse(req.url).path
: req.url;

outgoing.path = path.join(targetPath, outgoingPath);

return outgoing;
};

Expand Down
25 changes: 24 additions & 1 deletion test/lib-http-proxy-common-test.js
Expand Up @@ -117,6 +117,29 @@ describe('lib/http-proxy/common.js', function () {

expect(outgoing.port).to.eql(443);
});

it('should keep the original target path in the outgoing path', function(){
var outgoing = {};
common.setupOutgoing(outgoing, {target:
{ path: 'some-path' }
}, { url : 'am' });

expect(outgoing.path).to.eql('some-path/am');
});

it('should keep the original forward path in the outgoing path', function(){
var outgoing = {};
common.setupOutgoing(outgoing, {
target: {},
forward: {
path: 'some-path'
}
}, {
url : 'am'
}, 'forward');

expect(outgoing.path).to.eql('some-path/am');
});
});

describe('#setupSocket', function () {
Expand Down Expand Up @@ -144,4 +167,4 @@ describe('lib/http-proxy/common.js', function () {
expect(socketConfig.keepalive).to.eql(true);
});
});
});
});

0 comments on commit a65021d

Please sign in to comment.