Skip to content

Commit d4bc685

Browse files
committed
Add cmd option for removing cookies
1 parent 515c31d commit d4bc685

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

bin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ program
3434
.option('-I, --header [header]', 'change the response header property for identifying cached responses')
3535
.option('-l, --log', 'print log output to console')
3636
.option('-t, --timeout [number]', 'proxy timeout in milliseconds', parseInt)
37+
.option('-d, --deleteCookieDoman', 'Remove the Domain portion of all cookies')
3738
.parse(process.argv);
3839

3940
let configOptions = {};
@@ -65,6 +66,7 @@ let dataPlayback = isDef(configOptions.dataPlayback) ? configOptions.dataPlaybac
6566
let dataRecord = isDef(configOptions.dataRecord) ? configOptions.dataRecord : isDef(program.disableRecord) ? !program.disableRecord : true;
6667
let showConsoleOutput = isDef(configOptions.showConsoleOutput) ? configOptions.showConsoleOutput : isDef(program.log) ? program.log : false;
6768
let proxyTimeout = configOptions.proxyTimeout ? parseInt(configOptions.proxyTimeout, 10) : program.timeout;
69+
let deleteCookieDomain = isDef(configOptions.deleteCookieDomain) ? configOptions.deleteCookieDomain : isDef(program.deleteCookieDomain) ? program.deleteCookieDomain : false;
6870

6971
let excludedRouteMatchers;
7072
if (configOptions.excludedRouteMatchers && configOptions.excludedRouteMatchers.length > 0) {
@@ -95,7 +97,8 @@ let jsonCachingProxy = new JsonCachingProxy({
9597
commandPrefix,
9698
proxyHeaderIdentifier,
9799
showConsoleOutput,
98-
proxyTimeout
100+
proxyTimeout,
101+
deleteCookieDomain
99102
});
100103

101104
jsonCachingProxy.start();

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class JsonCachingProxy {
2525
dataPlayback: true,
2626
dataRecord: true,
2727
showConsoleOutput: false,
28-
proxyTimeout: 3600000 // one hour
28+
proxyTimeout: 3600000, // one hour
29+
deleteCookieDomain: false,
2930
};
3031

3132
// Ignore undefined values and combine the options with defaults
@@ -361,7 +362,7 @@ class JsonCachingProxy {
361362
res.location(urlUtil.parse(location).path);
362363
}
363364

364-
if (res._headers['set-cookie']) {
365+
if (this.options.deleteCookieDomain && res._headers['set-cookie']) {
365366
res.header('set-cookie', this.removeCookiesDomain(res._headers['set-cookie'] || []));
366367
}
367368

@@ -406,6 +407,7 @@ class JsonCachingProxy {
406407
this.log(`Command prefix: \t${chalk.bold(this.options.commandPrefix)}`);
407408
this.log(`Proxy response header: \t${chalk.bold(this.options.proxyHeaderIdentifier)}`);
408409
this.log(`Cache all: \t\t${chalk.bold(this.options.cacheEverything)}`);
410+
this.log(`Delete cookies domain: \t${chalk.bold(this.options.deleteCookieDomain)}`);
409411
this.log(`Cache busting params: \t${chalk.bold(this.options.cacheBustingParams)}`);
410412
this.log(`Excluded routes: `);
411413
this.options.excludedRouteMatchers.forEach((regExp) => {

0 commit comments

Comments
 (0)