diff --git a/packages/core/src/main/__test__/lens-proxy.test.ts b/packages/core/src/main/__test__/lens-proxy.test.ts index 20af162f17..665b890d33 100644 --- a/packages/core/src/main/__test__/lens-proxy.test.ts +++ b/packages/core/src/main/__test__/lens-proxy.test.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { isLongRunningRequest } from "../lens-proxy/lens-proxy"; +import { isLongRunningRequest } from "../lens-proxy/is-long-running-request"; describe("isLongRunningRequest", () => { it("returns true on watches", () => { diff --git a/packages/core/src/main/lens-proxy/disallowed-ports.ts b/packages/core/src/main/lens-proxy/disallowed-ports.ts new file mode 100644 index 0000000000..00c734ba17 --- /dev/null +++ b/packages/core/src/main/lens-proxy/disallowed-ports.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +/** + * This is the list of ports that chrome considers unsafe to allow HTTP + * connections to. Because they are the standard ports for processes that are + * too forgiving in the connection types they accept. + * + * If we get one of these ports, the easiest thing to do is to just try again. + * + * Source: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/port_util.cc + */ +export const disallowedPorts = new Set([ + 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79, + 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137, + 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532, + 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723, + 2049, 3659, 4045, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6697, + 10080, +]); diff --git a/packages/core/src/main/lens-proxy/is-long-running-request.ts b/packages/core/src/main/lens-proxy/is-long-running-request.ts new file mode 100644 index 0000000000..08a96dc2b4 --- /dev/null +++ b/packages/core/src/main/lens-proxy/is-long-running-request.ts @@ -0,0 +1,14 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getBoolean } from "../utils/parse-query"; + +const watchParam = "watch"; +const followParam = "follow"; + +export function isLongRunningRequest(reqUrl: string) { + const url = new URL(reqUrl, "http://localhost"); + + return getBoolean(url.searchParams, watchParam) || getBoolean(url.searchParams, followParam); +} diff --git a/packages/core/src/main/lens-proxy/lens-proxy.ts b/packages/core/src/main/lens-proxy/lens-proxy.ts index 94fb8a4eb2..5e8993cdb3 100644 --- a/packages/core/src/main/lens-proxy/lens-proxy.ts +++ b/packages/core/src/main/lens-proxy/lens-proxy.ts @@ -11,13 +11,14 @@ import { apiPrefix, apiKubePrefix } from "../../common/vars"; import type { RouteRequest } from "../router/route-request.injectable"; import type { Cluster } from "../../common/cluster/cluster"; import type { ProxyApiRequestArgs } from "./proxy-functions"; -import { getBoolean } from "../utils/parse-query"; import assert from "assert"; import type { SetRequired } from "type-fest"; import type { EmitAppEvent } from "../../common/app-event-bus/emit-event.injectable"; import type { Logger } from "../../common/logger"; import type { SelfSignedCert } from "selfsigned"; import type { KubeAuthProxyServer } from "../cluster/kube-auth-proxy-server.injectable"; +import { isLongRunningRequest } from "./is-long-running-request"; +import { disallowedPorts } from "./disallowed-ports"; export type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | undefined; export type ServerIncomingMessage = SetRequired; @@ -37,33 +38,6 @@ interface Dependencies { readonly certificate: SelfSignedCert; } -const watchParam = "watch"; -const followParam = "follow"; - -export function isLongRunningRequest(reqUrl: string) { - const url = new URL(reqUrl, "http://localhost"); - - return getBoolean(url.searchParams, watchParam) || getBoolean(url.searchParams, followParam); -} - -/** - * This is the list of ports that chrome considers unsafe to allow HTTP - * conntections to. Because they are the standard ports for processes that are - * too forgiving in the connection types they accept. - * - * If we get one of these ports, the easiest thing to do is to just try again. - * - * Source: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/net/base/port_util.cc - */ -const disallowedPorts = new Set([ - 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79, - 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137, - 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532, - 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723, - 2049, 3659, 4045, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669, 6697, - 10080, -]); - export class LensProxy { protected proxyServer: https.Server; protected closed = false;