Skip to content

Commit 6e64526

Browse files
committed
move shouldPassThrough to util file
1 parent 1dbaee5 commit 6e64526

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/server/http-combo-server.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { URLPattern } from "urlpattern-polyfill";
1919
import { TlsHandshakeFailure } from '../types';
2020
import { getCA } from '../util/tls';
2121
import { delay } from '../util/util';
22+
import { shouldPassThrough } from '../util/server-utils';
2223
import {
2324
getParentSocket,
2425
buildSocketTimingInfo,
@@ -421,22 +422,3 @@ function analyzeAndMaybePassThroughTls(
421422
tlsConnectionListener.call(server, socket);
422423
});
423424
}
424-
425-
export function shouldPassThrough(
426-
hostname: string | undefined,
427-
// Only one of these two should have values (validated above):
428-
passThroughPatterns: URLPattern[],
429-
interceptOnlyPatterns: URLPattern[] | undefined
430-
): boolean {
431-
if (!hostname) return false;
432-
433-
if (interceptOnlyPatterns) {
434-
return !interceptOnlyPatterns.some((pattern) =>
435-
pattern.test(`https://${hostname}`)
436-
);
437-
}
438-
439-
return passThroughPatterns.some((pattern) =>
440-
pattern.test(`https://${hostname}`)
441-
);
442-
}

src/util/server-utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function shouldPassThrough(
2+
hostname: string | undefined,
3+
// Only one of these two should have values (validated above):
4+
passThroughPatterns: URLPattern[],
5+
interceptOnlyPatterns: URLPattern[] | undefined
6+
): boolean {
7+
if (!hostname) return false;
8+
9+
if (interceptOnlyPatterns) {
10+
return !interceptOnlyPatterns.some((pattern) =>
11+
pattern.test(`https://${hostname}`)
12+
);
13+
}
14+
15+
return passThroughPatterns.some((pattern) =>
16+
pattern.test(`https://${hostname}`)
17+
);
18+
}

test/http-combo-server.spec.ts renamed to test/server-utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { URLPattern } from "urlpattern-polyfill";
2-
import { shouldPassThrough } from "../src/server/http-combo-server";
32
import { expect } from "./test-utils";
3+
import { shouldPassThrough } from "../src/util/server-utils";
44

55
describe("shouldPassThrough", () => {
66
it("should return false when passThroughHostnames is empty and interceptOnlyHostnames is undefined", async () => {

0 commit comments

Comments
 (0)