Skip to content

Commit 183b5bb

Browse files
gabrielboucherjcrugzz
authored andcommitted
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
1 parent 3a347af commit 183b5bb

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ proxyServer.listen(8015);
334334
* **localAddress**: Local interface string to bind for outgoing connections
335335
* **changeOrigin**: true/false, Default: false - changes the origin of the host header to the target URL
336336
* **auth**: Basic authentication i.e. 'user:password' to compute an Authorization header.
337-
* **hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects.
338-
* **autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
339-
* **protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
337+
* **hostRewrite**: rewrites the location hostname on (201/301/302/307/308) redirects.
338+
* **autoRewrite**: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
339+
* **protocolRewrite**: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
340340
* **headers**: object with extra headers to be added to target requests.
341341

342342
**NOTE:**

lib/http-proxy/passes/web-outgoing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var url = require('url'),
22
passes = exports;
33

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

66
/*!
77
* Array of passes.

test/lib-http-proxy-passes-web-outgoing-test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
2424
beforeEach(function() {
2525
this.options.hostRewrite = "ext-manual.com";
2626
});
27-
[301, 302, 307, 308].forEach(function(code) {
27+
[201, 301, 302, 307, 308].forEach(function(code) {
2828
it('on ' + code, function() {
2929
this.proxyRes.statusCode = code;
3030
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -69,7 +69,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
6969
beforeEach(function() {
7070
this.options.autoRewrite = true;
7171
});
72-
[301, 302, 307, 308].forEach(function(code) {
72+
[201, 301, 302, 307, 308].forEach(function(code) {
7373
it('on ' + code, function() {
7474
this.proxyRes.statusCode = code;
7575
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -108,7 +108,7 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
108108
beforeEach(function() {
109109
this.options.protocolRewrite = 'https';
110110
});
111-
[301, 302, 307, 308].forEach(function(code) {
111+
[201, 301, 302, 307, 308].forEach(function(code) {
112112
it('on ' + code, function() {
113113
this.proxyRes.statusCode = code;
114114
httpProxy.setRedirectHostRewrite(this.req, {}, this.proxyRes, this.options);
@@ -241,4 +241,3 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
241241
});
242242

243243
});
244-

0 commit comments

Comments
 (0)