mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #693 from EndangeredMassa/fix-path
Allow proxy to maintain the original target path
This commit is contained in:
commit
814fbd254d
@ -1,4 +1,5 @@
|
||||
var common = exports,
|
||||
path = require('path'),
|
||||
url = require('url'),
|
||||
extend = require('util')._extend;
|
||||
|
||||
@ -57,13 +58,22 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
|
||||
) { outgoing.headers.connection = 'close'; }
|
||||
}
|
||||
|
||||
|
||||
// the final path is target path + relative path requested by user:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@ -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 () {
|
||||
@ -144,4 +167,4 @@ describe('lib/http-proxy/common.js', function () {
|
||||
expect(socketConfig.keepalive).to.eql(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user