Add some more comments on why http / https is handled in different code paths

This commit is contained in:
Sander Declerck 2025-10-15 11:56:03 +02:00
parent 37ef3e187b
commit 05354ba2f0
No known key found for this signature in database
2 changed files with 7 additions and 1 deletions

View file

@ -4,6 +4,9 @@ import * as https from "https";
export function handleHttpProxyRequest(req, res) {
const url = new URL(req.url);
// The protocol for the plainHttpProxy should usually only be http:
// but when the client for some reason sends an https: request directly
// instead of using the CONNECT method, we should handle it gracefully.
let protocol;
if (url.protocol === "http:") {
protocol = http;

View file

@ -55,7 +55,10 @@ export function mergeSafeChainProxyEnvironmentVariables(env) {
function createProxyServer() {
const server = http.createServer(
handleHttpProxyRequest // This handles plain HTTP requests
// This handles direct HTTP requests (non-CONNECT requests)
// This is normally http-only traffic, but we also handle
// https for clients that don't properly use CONNECT
handleHttpProxyRequest
);
// This handles HTTPS requests via the CONNECT method