Skip to content

Commit

Permalink
Location rewriting for responses with status 201 (#1024)
Browse files Browse the repository at this point in the history
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 183b5bb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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:**
Expand Down
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/web-outgoing.js
@@ -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.
Expand Down
7 changes: 3 additions & 4 deletions test/lib-http-proxy-passes-web-outgoing-test.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -241,4 +241,3 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
});

});

0 comments on commit 183b5bb

Please sign in to comment.