From f5c2381395e01bf8d6655cc70e14032c8f0aaa67 Mon Sep 17 00:00:00 2001 From: Sean Willis Date: Tue, 20 Feb 2018 20:53:39 -0800 Subject: [PATCH] Updating docs and adding more tests. --- README.md | 12 ++++++ ...lib-http-proxy-passes-web-outgoing-test.js | 38 ++++++++++++++----- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e7eebc3..4a56ff6 100644 --- a/README.md +++ b/README.md @@ -342,6 +342,18 @@ proxyServer.listen(8015); "*": "" } ``` +* **cookiePathRewrite**: rewrites path of `set-cookie` headers. Possible values: + * `false` (default): disable cookie rewriting + * String: new path, for example `cookiePathRewrite: "/newPath/"`. To remove the path, use `cookiePathRewrite: ""`. To set path to root use `cookiePathRewrite: "/"`. + * Object: mapping of paths to new paths, use `"*"` to match all paths. + For example keep one path unchanged, rewrite one path and remove other paths: + ``` + cookiePathRewrite: { + "/unchanged.path/": "/unchanged.path/", + "/old.path/": "/new.path/", + "*": "" + } + ``` * **headers**: object with extra headers to be added to target requests. * **proxyTimeout**: timeout (in millis) when proxy receives no response from target diff --git a/test/lib-http-proxy-passes-web-outgoing-test.js b/test/lib-http-proxy-passes-web-outgoing-test.js index aef521c..a509cf1 100644 --- a/test/lib-http-proxy-passes-web-outgoing-test.js +++ b/test/lib-http-proxy-passes-web-outgoing-test.js @@ -289,15 +289,6 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () { expect(this.res.headers['set-cookie']).to.have.length(2); }); - it('does not rewrite domain', function() { - var options = {}; - - httpProxy.writeHeaders({}, this.res, this.proxyRes, options); - - expect(this.res.headers['set-cookie']) - .to.contain('hello; domain=my.domain; path=/'); - }); - it('rewrites path', function() { var options = { cookiePathRewrite: '/dummyPath' @@ -309,6 +300,35 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () { .to.contain('hello; domain=my.domain; path=/dummyPath'); }); + it('does not rewrite path', function() { + var options = {}; + + httpProxy.writeHeaders({}, this.res, this.proxyRes, options); + + expect(this.res.headers['set-cookie']) + .to.contain('hello; domain=my.domain; path=/'); + }); + + it('removes path', function() { + var options = { + cookiePathRewrite: '' + }; + + httpProxy.writeHeaders({}, this.res, this.proxyRes, options); + + expect(this.res.headers['set-cookie']) + .to.contain('hello; domain=my.domain'); + }); + + it('does not rewrite domain', function() { + var options = {}; + + httpProxy.writeHeaders({}, this.res, this.proxyRes, options); + + expect(this.res.headers['set-cookie']) + .to.contain('hello; domain=my.domain; path=/'); + }); + it('rewrites domain', function() { var options = { cookieDomainRewrite: 'my.new.domain'