MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / forwardClientOrigin

Function forwardClientOrigin

scripts/proxy-utils.mjs:49–71  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

47// host, so forward it with the browser-visible port: code-server appends
48// X-Forwarded-Port when X-Forwarded-Host carries none.
49function 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
73function parseBackendUrl(backendUrl) {
74 const url = new URL(backendUrl);

Callers 2

proxyHttpFunction · 0.85
proxyWebSocketFunction · 0.85

Calls 1

firstForwardedValueFunction · 0.85

Tested by

no test coverage detected