Compare commits

...

3 Commits

Author SHA1 Message Date
Jarrett Cruger
c82f5dfc62 [dist] Version bump. 1.4.0 2014-09-11 18:51:35 -04:00
Jarrett Cruger
937b853c33 [test] add test for prependPath option 2014-09-11 18:44:28 -04:00
Jarrett Cruger
b8c40aa58f [api] add prependPath option to go with path change 2014-09-11 18:42:47 -04:00
5 changed files with 19 additions and 5 deletions

View File

@ -38,6 +38,7 @@ module.exports.createProxyServer =
* xfwd : <true/false, adds x-forward headers> * xfwd : <true/false, adds x-forward headers>
* 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>
* localAddress : <Local interface string to bind for outgoing connections> * localAddress : <Local interface string to bind for outgoing connections>
* } * }
* *

View File

@ -61,7 +61,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
// the final path is target path + relative path requested by user: // the final path is target path + relative path requested by user:
var target = options[forward || 'target']; var target = options[forward || 'target'];
var targetPath = target var targetPath = target && options.prependPath !== false
? (target.path || '') ? (target.path || '')
: ''; : '';

View File

@ -89,6 +89,9 @@ httpProxy.createRightProxy = createRightProxy;
function ProxyServer(options) { function ProxyServer(options) {
EE3.call(this); EE3.call(this);
options = options || {};
options.prependPath = options.prependPath === false ? false : true;
this.web = this.proxyRequest = createRightProxy('web')(options); this.web = this.proxyRequest = createRightProxy('web')(options);
this.ws = this.proxyWebsocketRequest = createRightProxy('ws')(options); this.ws = this.proxyWebsocketRequest = createRightProxy('ws')(options);
this.options = options; this.options = options;

View File

@ -1,6 +1,6 @@
{ {
"name" : "http-proxy", "name" : "http-proxy",
"version" : "1.3.1", "version" : "1.4.0",
"repository" : { "repository" : {
"type" : "git", "type" : "git",

View File

@ -20,7 +20,7 @@ describe('lib/http-proxy/common.js', function () {
{ {
method : 'i', method : 'i',
url : 'am', url : 'am',
headers : {'pro':'xy','overwritten':false} headers : {'pro':'xy','overwritten':false}
}); });
expect(outgoing.host).to.eql('hey'); expect(outgoing.host).to.eql('hey');
@ -91,7 +91,7 @@ describe('lib/http-proxy/common.js', function () {
it('set the port according to the protocol', function () { it('set the port according to the protocol', function () {
var outgoing = {}; var outgoing = {};
common.setupOutgoing(outgoing, common.setupOutgoing(outgoing,
{ {
agent : '?', agent : '?',
target: { target: {
host : 'how', host : 'how',
@ -103,7 +103,7 @@ describe('lib/http-proxy/common.js', function () {
{ {
method : 'i', method : 'i',
url : 'am', url : 'am',
headers : 'proxy' headers : 'proxy'
}); });
expect(outgoing.host).to.eql('how'); expect(outgoing.host).to.eql('how');
@ -140,6 +140,16 @@ describe('lib/http-proxy/common.js', function () {
expect(outgoing.path).to.eql('some-path/am'); expect(outgoing.path).to.eql('some-path/am');
}); });
it('should not prepend the target path to the outgoing path with prependPath = false', function () {
var outgoing = {};
common.setupOutgoing(outgoing, {
target: { path: 'hellothere' },
prependPath: false
}, { url: 'hi' });
expect(outgoing.path).to.eql('hi');
})
}); });
describe('#setupSocket', function () { describe('#setupSocket', function () {