Skip to content

Commit f5c2381

Browse files
Sean Willisindexzero
Sean Willis
authored andcommitted
Updating docs and adding more tests.
1 parent 50f58b4 commit f5c2381

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ proxyServer.listen(8015);
342342
"*": ""
343343
}
344344
```
345+
* **cookiePathRewrite**: rewrites path of `set-cookie` headers. Possible values:
346+
* `false` (default): disable cookie rewriting
347+
* String: new path, for example `cookiePathRewrite: "/newPath/"`. To remove the path, use `cookiePathRewrite: ""`. To set path to root use `cookiePathRewrite: "/"`.
348+
* Object: mapping of paths to new paths, use `"*"` to match all paths.
349+
For example keep one path unchanged, rewrite one path and remove other paths:
350+
```
351+
cookiePathRewrite: {
352+
"/unchanged.path/": "/unchanged.path/",
353+
"/old.path/": "/new.path/",
354+
"*": ""
355+
}
356+
```
345357
* **headers**: object with extra headers to be added to target requests.
346358
* **proxyTimeout**: timeout (in millis) when proxy receives no response from target
347359

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,18 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
289289
expect(this.res.headers['set-cookie']).to.have.length(2);
290290
});
291291

292-
it('does not rewrite domain', function() {
292+
it('rewrites path', function() {
293+
var options = {
294+
cookiePathRewrite: '/dummyPath'
295+
};
296+
297+
httpProxy.writeHeaders({}, this.res, this.proxyRes, options);
298+
299+
expect(this.res.headers['set-cookie'])
300+
.to.contain('hello; domain=my.domain; path=/dummyPath');
301+
});
302+
303+
it('does not rewrite path', function() {
293304
var options = {};
294305

295306
httpProxy.writeHeaders({}, this.res, this.proxyRes, options);
@@ -298,15 +309,24 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () {
298309
.to.contain('hello; domain=my.domain; path=/');
299310
});
300311

301-
it('rewrites path', function() {
312+
it('removes path', function() {
302313
var options = {
303-
cookiePathRewrite: '/dummyPath'
314+
cookiePathRewrite: ''
304315
};
305316

306317
httpProxy.writeHeaders({}, this.res, this.proxyRes, options);
307318

308319
expect(this.res.headers['set-cookie'])
309-
.to.contain('hello; domain=my.domain; path=/dummyPath');
320+
.to.contain('hello; domain=my.domain');
321+
});
322+
323+
it('does not rewrite domain', function() {
324+
var options = {};
325+
326+
httpProxy.writeHeaders({}, this.res, this.proxyRes, options);
327+
328+
expect(this.res.headers['set-cookie'])
329+
.to.contain('hello; domain=my.domain; path=/');
310330
});
311331

312332
it('rewrites domain', function() {

0 commit comments

Comments
 (0)