diff --git a/src/dev/server.ts b/src/dev/server.ts index 64dffe5dd8..9be1b0e32b 100644 --- a/src/dev/server.ts +++ b/src/dev/server.ts @@ -158,14 +158,14 @@ export function createDevServer(nitro: Nitro): NitroDevServer { // Main worker proxy const proxy = createProxy(); proxy.proxy.on("proxyReq", (proxyReq, req) => { - // TODO: Avoid overwriting headers if already set - if (req.socket.remoteAddress) { + const proxyRequestHeaders = proxyReq.getHeaders(); + if (req.socket.remoteAddress && !proxyRequestHeaders["x-forwarded-for"]) { proxyReq.setHeader("X-Forwarded-For", req.socket.remoteAddress); } - if (req.socket.remotePort) { + if (req.socket.remotePort && !proxyRequestHeaders["x-forwarded-port"]) { proxyReq.setHeader("X-Forwarded-Port", req.socket.remotePort); } - if (req.socket.remoteFamily) { + if (req.socket.remoteFamily && !proxyRequestHeaders["x-forwarded-proto"]) { proxyReq.setHeader("X-Forwarded-Proto", req.socket.remoteFamily); } });