(req)
| 47 | // host, so forward it with the browser-visible port: code-server appends |
| 48 | // X-Forwarded-Port when X-Forwarded-Host carries none. |
| 49 | function forwardClientOrigin(req) { |
| 50 | const host = |
| 51 | firstForwardedValue(req.headers["x-forwarded-host"]) || req.headers.host; |
| 52 | if (!host) return; |
| 53 | const proto = |
| 54 | firstForwardedValue(req.headers["x-forwarded-proto"]) || |
| 55 | (req.socket.encrypted ? "https" : "http"); |
| 56 | let hasPort = false; |
| 57 | try { |
| 58 | hasPort = new URL(`http://${host}`).port !== ""; |
| 59 | } catch { |
| 60 | // Malformed Host: forward it untouched and let the upstream reject it. |
| 61 | return; |
| 62 | } |
| 63 | req.headers["x-forwarded-host"] = host; |
| 64 | req.headers["x-forwarded-proto"] = proto; |
| 65 | if (!hasPort) { |
| 66 | // Traefik reports "wss" on upgrades. |
| 67 | req.headers["x-forwarded-port"] = /^(https|wss)$/i.test(proto) |
| 68 | ? "443" |
| 69 | : "80"; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | function parseBackendUrl(backendUrl) { |
| 74 | const url = new URL(backendUrl); |
no test coverage detected