Skip to content

Commit d3726bd

Browse files
committed
feat(repeater): add --proxy-domains-bypass flag
this flag allows specific requests with URLs matching any of the hosts provided in the flag’s input to bypass the proxy when it is enabled.
1 parent 557bd5d commit d3726bd

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/Commands/RunRepeater.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,19 @@ export class RunRepeater implements CommandModule {
135135
requiresArg: true,
136136
array: true,
137137
describe:
138-
'Comma-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option'
138+
'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option'
139+
})
140+
.option('proxy-domains-bypass', {
141+
requiresArg: true,
142+
array: true,
143+
describe:
144+
'Space-separated list of domains that should not be routed through the proxy. This option is only applicable when using the --proxy option'
139145
})
140146
.conflicts({
141147
daemon: 'remove-daemon',
142-
ntlm: [
143-
'proxy',
144-
'proxy-bright',
145-
'proxy-target',
146-
'experimental-connection-reuse'
147-
]
148+
ntlm: ['proxy', 'experimental-connection-reuse']
148149
})
150+
.conflicts('proxy-domains', 'proxy-domains-bypass')
149151
.env('REPEATER')
150152
.middleware((args: Arguments) => {
151153
if (Object.hasOwnProperty.call(args, '')) {
@@ -196,7 +198,8 @@ export class RunRepeater implements CommandModule {
196198
{ type: 'application/ld+json', allowTruncation: false },
197199
{ type: 'application/graphql', allowTruncation: false }
198200
],
199-
proxyDomains: args.proxyDomains as string[]
201+
proxyDomains: args.proxyDomains as string[],
202+
proxyDomainsBypass: args.proxyDomainsBypass as string[]
200203
}
201204
})
202205
.register<DefaultRepeaterServerOptions>(

src/RequestExecutor/HttpRequestExecutor.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class HttpRequestExecutor implements RequestExecutor {
4040
private readonly httpAgent?: http.Agent;
4141
private readonly httpsAgent?: https.Agent;
4242
private readonly proxyDomains?: RegExp[];
43+
private readonly proxyDomainsBypass?: RegExp[];
4344

4445
get protocol(): Protocol {
4546
return Protocol.HTTP;
@@ -67,11 +68,23 @@ export class HttpRequestExecutor implements RequestExecutor {
6768
this.httpAgent = new http.Agent(agentOptions);
6869
}
6970

71+
if (this.options.proxyDomains && this.options.proxyDomainsBypass) {
72+
throw new Error(
73+
'cannot use both proxyDomains and proxyDomainsBypass at the same time'
74+
);
75+
}
76+
7077
if (this.options.proxyDomains) {
7178
this.proxyDomains = this.options.proxyDomains.map((domain) =>
7279
Helpers.wildcardToRegExp(domain)
7380
);
7481
}
82+
83+
if (this.options.proxyDomainsBypass) {
84+
this.proxyDomainsBypass = this.options.proxyDomainsBypass.map((domain) =>
85+
Helpers.wildcardToRegExp(domain)
86+
);
87+
}
7588
}
7689

7790
public async execute(options: Request): Promise<Response> {
@@ -197,12 +210,27 @@ export class HttpRequestExecutor implements RequestExecutor {
197210
}
198211

199212
private getRequestAgent(options: Request) {
213+
// do not use proxy for domains that are not in the list
200214
if (
201215
this.proxyDomains &&
202216
!this.proxyDomains.some((domain) =>
203217
domain.test(parseUrl(options.url).hostname)
204218
)
205219
) {
220+
logger.debug("Not using proxy for URL '%s'", options.url);
221+
222+
return options.secureEndpoint ? this.httpsAgent : this.httpAgent;
223+
}
224+
225+
// do not use proxy for domains that are in the bypass list
226+
if (
227+
this.proxyDomainsBypass &&
228+
this.proxyDomainsBypass.some((domain) =>
229+
domain.test(parseUrl(options.url).hostname)
230+
)
231+
) {
232+
logger.debug("Bypassing proxy for URL '%s'", options.url);
233+
206234
return options.secureEndpoint ? this.httpsAgent : this.httpAgent;
207235
}
208236

src/RequestExecutor/RequestExecutorOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface RequestExecutorOptions {
1515
maxContentLength?: number;
1616
reuseConnection?: boolean;
1717
proxyDomains?: string[];
18+
proxyDomainsBypass?: string[];
1819
}
1920

2021
export const RequestExecutorOptions: unique symbol = Symbol(

0 commit comments

Comments
 (0)