From 14c79d7c038bf589a0029f50b95bc63774a11ba6 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 25 Mar 2026 21:30:58 +0100 Subject: [PATCH 1/2] fix(web-incoming): use `isSSL` regex for consistent https/wss protocol checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream: http-party/node-http-proxy#1419 The forward, target, and redirect code paths used `=== "https:"` which missed `wss:` and other SSL protocol variants. The rest of the codebase already uses the shared `isSSL` regex — align these three call sites. --- src/index.ts | 2 +- src/middleware/web-incoming.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6f8a34a..f5598ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ export type { ProxyAddr, ProxyServerOptions, ProxyTarget, ProxyTargetDetailed } from "./types.ts"; export { ProxyServer, createProxyServer, type ProxyServerEventMap } from "./server.ts"; -export { proxyFetch } from "./fetch.ts"; +export { proxyFetch, type ProxyFetchOptions } from "./fetch.ts"; export { proxyUpgrade, type ProxyUpgradeOptions } from "./ws.ts"; diff --git a/src/middleware/web-incoming.ts b/src/middleware/web-incoming.ts index 09dbda4..bdc8d4f 100644 --- a/src/middleware/web-incoming.ts +++ b/src/middleware/web-incoming.ts @@ -2,7 +2,7 @@ import type { ClientRequest, IncomingMessage, ServerResponse } from "node:http"; import type { ProxyTargetDetailed } from "../types.ts"; import nodeHTTP from "node:http"; import nodeHTTPS from "node:https"; -import { getPort, hasEncryptedConnection, setupOutgoing } from "../_utils.ts"; +import { getPort, hasEncryptedConnection, isSSL, setupOutgoing } from "../_utils.ts"; import { webOutgoingMiddleware } from "./web-outgoing.ts"; import { type ProxyMiddleware, defineProxyMiddleware } from "./_utils.ts"; @@ -78,7 +78,7 @@ export const stream = defineProxyMiddleware((req, res, options, server, head, ca if (options.forward) { // If forward enable, so just pipe the request - const forwardReq = (options.forward.protocol === "https:" ? https : http).request( + const forwardReq = (isSSL.test(options.forward.protocol || "http") ? https : http).request( setupOutgoing(options.ssl || {}, options, req, "forward"), ); @@ -96,7 +96,7 @@ export const stream = defineProxyMiddleware((req, res, options, server, head, ca } // Request initalization - const proxyReq = (options.target.protocol === "https:" ? https : http).request( + const proxyReq = (isSSL.test(options.target.protocol || "http") ? https : http).request( setupOutgoing(options.ssl || {}, options, req), ); @@ -186,7 +186,7 @@ export const stream = defineProxyMiddleware((req, res, options, server, head, ca const preserveMethod = statusCode === 307 || statusCode === 308; const redirectMethod = preserveMethod ? req.method || "GET" : "GET"; - const isHTTPS = location.protocol === "https:"; + const isHTTPS = isSSL.test(location.protocol); const agent = isHTTPS ? https : http; // Build headers from original request From 538499b007112b2683cf551b366c0ae45e46c6ac Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 25 Mar 2026 21:32:37 +0100 Subject: [PATCH 2/2] Apply suggestion from @pi0 --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f5598ab..6f8a34a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ export type { ProxyAddr, ProxyServerOptions, ProxyTarget, ProxyTargetDetailed } from "./types.ts"; export { ProxyServer, createProxyServer, type ProxyServerEventMap } from "./server.ts"; -export { proxyFetch, type ProxyFetchOptions } from "./fetch.ts"; +export { proxyFetch } from "./fetch.ts"; export { proxyUpgrade, type ProxyUpgradeOptions } from "./ws.ts";