mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #759 from nodejitsu/ignore-path
[api] add an ignorePath option if you want to disregard the path of the ...
This commit is contained in:
commit
0db8f195d7
@ -39,6 +39,7 @@ module.exports.createProxyServer =
|
|||||||
* secure : <true/false, verify SSL certificate>
|
* secure : <true/false, verify SSL certificate>
|
||||||
* toProxy: <true/false, explicitly specify if we are proxying to another proxy>
|
* toProxy: <true/false, explicitly specify if we are proxying to another proxy>
|
||||||
* prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>
|
* prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>
|
||||||
|
* ignorePath: <true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request>
|
||||||
* localAddress : <Local interface string to bind for outgoing connections>
|
* localAddress : <Local interface string to bind for outgoing connections>
|
||||||
* changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
|
* changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
|
||||||
* auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
|
* auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
|
||||||
|
|||||||
@ -83,6 +83,13 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
|
|||||||
? (url.parse(req.url).path || '/')
|
? (url.parse(req.url).path || '/')
|
||||||
: req.url;
|
: req.url;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remark: ignorePath will just straight up ignore whatever the request's
|
||||||
|
// path is. This can be labeled as FOOT-GUN material if you do not know what
|
||||||
|
// you are doing and are using conflicting options.
|
||||||
|
//
|
||||||
|
outgoingPath = !options.ignorePath ? outgoingPath : '/';
|
||||||
|
|
||||||
outgoing.path = common.urlJoin(targetPath, outgoingPath);
|
outgoing.path = common.urlJoin(targetPath, outgoingPath);
|
||||||
|
|
||||||
if (options.changeOrigin) {
|
if (options.changeOrigin) {
|
||||||
@ -175,9 +182,7 @@ common.urlJoin = function() {
|
|||||||
// joining e.g. ['', 'am']
|
// joining e.g. ['', 'am']
|
||||||
//
|
//
|
||||||
retSegs = [
|
retSegs = [
|
||||||
args.filter(function filter(a) {
|
args.filter(Boolean).join('/').replace(/\/+/g, '/').replace(/:\//g, '://')
|
||||||
return !!a;
|
|
||||||
}).join('/').replace(/\/+/g, '/').replace(/:\//g, '://')
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Only join the query string if it exists so we don't have trailing a '?'
|
// Only join the query string if it exists so we don't have trailing a '?'
|
||||||
|
|||||||
@ -241,6 +241,31 @@ describe('lib/http-proxy/common.js', function () {
|
|||||||
expect(outgoing.path).to.eql('/' + google);
|
expect(outgoing.path).to.eql('/' + google);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when using ignorePath', function () {
|
||||||
|
it('should ignore the path of the `req.url` passed in but use the target path', function () {
|
||||||
|
var outgoing = {};
|
||||||
|
var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo';
|
||||||
|
common.setupOutgoing(outgoing, {
|
||||||
|
target: url.parse(myEndpoint),
|
||||||
|
ignorePath: true
|
||||||
|
}, { url: '/more/crazy/pathness' });
|
||||||
|
|
||||||
|
expect(outgoing.path).to.eql('/some/crazy/path/whoooo/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('and prependPath: false, it should ignore path of target and incoming request', function () {
|
||||||
|
var outgoing = {};
|
||||||
|
var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo';
|
||||||
|
common.setupOutgoing(outgoing, {
|
||||||
|
target: url.parse(myEndpoint),
|
||||||
|
ignorePath: true,
|
||||||
|
prependPath: false
|
||||||
|
}, { url: '/more/crazy/pathness' });
|
||||||
|
|
||||||
|
expect(outgoing.path).to.eql('/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when using changeOrigin', function () {
|
describe('when using changeOrigin', function () {
|
||||||
it('should correctly set the port to the host when it is a non-standard port using url.parse', function () {
|
it('should correctly set the port to the host when it is a non-standard port using url.parse', function () {
|
||||||
var outgoing = {};
|
var outgoing = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user