Skip to content
Permalink
Browse files

Location rewriting for responses with status 201 (#1024)

Implement rewriting of the location header for responses with status code 201, according to RFC2616 section 10.2.2
  • Loading branch information...
gabrielboucher authored and jcrugzz committed Aug 11, 2016
1 parent 3a347af commit 183b5bb4fc0a8cf0c08b2e949319dd3a2f134c5e
Showing with 7 additions and 8 deletions.
  1. +3 −3 README.md
  2. +1 −1 lib/http-proxy/passes/web-outgoing.js
  3. +3 −4 test/lib-http-proxy-passes-web-outgoing-test.js
@@ -334,9 +334,9 @@ proxyServer.listen(8015);
* **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
* **auth**: Basic authentication i.e. 'user:password' to compute an Authorization header.
* **hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects.
* **autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
* **protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
* **hostRewrite**: rewrites the location hostname on (201/301/302/307/308) redirects.
* **autoRewrite**: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
* **protocolRewrite**: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
* **headers**: object with extra headers to be added to target requests.
**NOTE:**
@@ -1,7 +1,7 @@
var url = require('url'),
passes = exports;

var redirectRegex = /^30(1|2|7|8)$/;
var redirectRegex = /^201|30(1|2|7|8)$/;

/*!
* Array of passes.
@@ -24,7 +24,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
beforeEach(function() {
this.options.hostRewrite = "ext-manual.com";
});
[301, 302, 307, 308].forEach(function(code) {
[201, 301, 302, 307, 308].forEach(function(code) {
it('on ' + code, function() {
this.proxyRes.statusCode = code;
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -69,7 +69,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
beforeEach(function() {
this.options.autoRewrite = true;
});
[301, 302, 307, 308].forEach(function(code) {
[201, 301, 302, 307, 308].forEach(function(code) {
it('on ' + code, function() {
this.proxyRes.statusCode = code;
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -108,7 +108,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
beforeEach(function() {
this.options.protocolRewrite = 'https';
});
[301, 302, 307, 308].forEach(function(code) {
[201, 301, 302, 307, 308].forEach(function(code) {
it('on ' + code, function() {
this.proxyRes.statusCode = code;
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -241,4 +241,3 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
});

});

0 comments on commit 183b5bb

Please sign in to comment.
You can’t perform that action at this time.