From 25182ff772482fb23dfd8533e3d4cf32e0ad10d6 Mon Sep 17 00:00:00 2001 From: 0x01001 <3379258+0x01001@users.noreply.github.com> Date: Thu, 7 May 2026 15:50:36 +0700 Subject: [PATCH] feat: add support for configurable tunnel transport protocols (#919) - Introduced DEFAULT_QUICK_TUNNEL_PROTOCOL and QUICK_TUNNEL_PROTOCOLS to allow users to specify the transport protocol for quick tunnels. - Updated spawnQuickTunnel function to utilize the specified protocol from environment variables, defaulting to HTTP/2 if not provided. - Enhanced the child process environment to include the selected tunnel transport protocol. --- src/lib/tunnel/cloudflared.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/tunnel/cloudflared.js b/src/lib/tunnel/cloudflared.js index 2fd4a50f..d16155ab 100644 --- a/src/lib/tunnel/cloudflared.js +++ b/src/lib/tunnel/cloudflared.js @@ -12,6 +12,8 @@ const IS_WINDOWS = os.platform() === "win32"; const BIN_NAME = IS_WINDOWS ? `${BINARY_NAME}.exe` : BINARY_NAME; const BIN_PATH = path.join(BIN_DIR, BIN_NAME); const POWERSHELL_HIDDEN_COMMAND = "powershell -NoProfile -NonInteractive -WindowStyle Hidden -Command"; +const DEFAULT_QUICK_TUNNEL_PROTOCOL = "http2"; +const QUICK_TUNNEL_PROTOCOLS = new Set(["http2", "quic", "auto"]); const GITHUB_BASE_URL = "https://github.com/cloudflare/cloudflared/releases/latest/download"; @@ -284,10 +286,16 @@ export async function spawnQuickTunnel(localPort, onUrlUpdate) { } catch (e) { /* ignore */ } }; - const child = spawn(binaryPath, ["tunnel", "--url", `http://localhost:${localPort}`, "--config", configPath, "--no-autoupdate"], { + const requestedProtocol = String(process.env.TUNNEL_TRANSPORT_PROTOCOL || process.env.CLOUDFLARED_PROTOCOL || DEFAULT_QUICK_TUNNEL_PROTOCOL).trim().toLowerCase(); + const tunnelProtocol = QUICK_TUNNEL_PROTOCOLS.has(requestedProtocol) ? requestedProtocol : DEFAULT_QUICK_TUNNEL_PROTOCOL; + const child = spawn(binaryPath, ["tunnel", "--url", `http://127.0.0.1:${localPort}`, "--config", configPath, "--no-autoupdate"], { detached: false, windowsHide: true, - stdio: ["ignore", "pipe", "pipe"] + env: { + ...process.env, + TUNNEL_TRANSPORT_PROTOCOL: tunnelProtocol, + }, + stdio: ["ignore", "pipe", "pipe"], }); cloudflaredProcess = child;