mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
📝 Add host rewrite docs and specs.
This commit is contained in:
parent
daf66a7a88
commit
add81338a9
@ -325,6 +325,7 @@ proxyServer.listen(8015);
|
|||||||
* **secure**: true/false, if you want to verify the SSL Certs
|
* **secure**: true/false, if you want to verify the SSL Certs
|
||||||
* **xfwd**: true/false, adds x-forward headers
|
* **xfwd**: true/false, adds x-forward headers
|
||||||
* **toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies)
|
* **toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies)
|
||||||
|
* **hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects.
|
||||||
|
|
||||||
If you are using the `proxyServer.listen` method, the following options are also applicable:
|
If you are using the `proxyServer.listen` method, the following options are also applicable:
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ module.exports.createProxyServer =
|
|||||||
* 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>
|
||||||
* 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>
|
||||||
|
* hostRewrite: rewrites the location hostname on (301/302/307/308) redirects, Default: null.
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* NOTE: `options.ws` and `options.ssl` are optional.
|
* NOTE: `options.ws` and `options.ssl` are optional.
|
||||||
|
|||||||
@ -2,6 +2,58 @@ var httpProxy = require('../lib/http-proxy/passes/web-outgoing'),
|
|||||||
expect = require('expect.js');
|
expect = require('expect.js');
|
||||||
|
|
||||||
describe('lib/http-proxy/passes/web-outgoing.js', function () {
|
describe('lib/http-proxy/passes/web-outgoing.js', function () {
|
||||||
|
describe('#setRedirectHostRewrite', function () {
|
||||||
|
context('rewrites location host to option', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.proxyRes = {
|
||||||
|
statusCode: 301,
|
||||||
|
headers: {
|
||||||
|
location: "http://f.com/"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.options = {
|
||||||
|
hostRewrite: "x.com"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('on 301', function() {
|
||||||
|
this.proxyRes.statusCode = 301;
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, this.options);
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('on 302', function() {
|
||||||
|
this.proxyRes.statusCode = 302;
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, this.options);
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('on 307', function() {
|
||||||
|
this.proxyRes.statusCode = 307;
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, this.options);
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('on 308', function() {
|
||||||
|
this.proxyRes.statusCode = 308;
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, this.options);
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://'+this.options.hostRewrite+'/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('not on 200', function() {
|
||||||
|
this.proxyRes.statusCode = 200;
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, this.options);
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('not when hostRewrite is unset', function() {
|
||||||
|
httpProxy.setRedirectHostRewrite({}, {}, this.proxyRes, {});
|
||||||
|
expect(this.proxyRes.headers.location).to.eql('http://f.com/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#setConnection', function () {
|
describe('#setConnection', function () {
|
||||||
it('set the right connection with 1.0 - `close`', function() {
|
it('set the right connection with 1.0 - `close`', function() {
|
||||||
var proxyRes = { headers: {} };
|
var proxyRes = { headers: {} };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user