MCPcopy Index your code
hub / github.com/coder/code-server / getHost

Function getHost

src/node/http.ts:414–439  ·  view source on GitHub ↗
(req: express.Request)

Source from the content-addressed store, hash-verified

412 * Get the host from headers. It will be trimmed and lowercased.
413 */
414export function getHost(req: express.Request): string | undefined {
415 // Honor Forwarded if present.
416 const forwardedRaw = getFirstHeader(req, "forwarded")
417 if (forwardedRaw) {
418 const parts = forwardedRaw.split(/[;,]/)
419 for (let i = 0; i < parts.length; ++i) {
420 const [key, value] = splitOnFirstEquals(parts[i])
421 if (key.trim().toLowerCase() === "host" && value) {
422 return value.trim().toLowerCase()
423 }
424 }
425 }
426
427 // Honor X-Forwarded-Host if present. Some reverse proxies will set multiple
428 // comma-separated hosts.
429 const xHost = getFirstHeader(req, "x-forwarded-host")
430 if (xHost) {
431 const firstXHost = xHost.split(",")[0]
432 if (firstXHost) {
433 return firstXHost.trim().toLowerCase()
434 }
435 }
436
437 const host = getFirstHeader(req, "host")
438 return host ? host.trim().toLowerCase() : undefined
439}

Callers 2

maybeProxyFunction · 0.90
authenticateOriginFunction · 0.85

Calls 2

splitOnFirstEqualsFunction · 0.90
getFirstHeaderFunction · 0.85

Tested by

no test coverage detected