{"record":{"id":"9eb3a1c7fc49864a","repo":"sveltejs/kit","slug":"could-not-determine-host-the-request-must-have-a","errorCode":null,"errorMessage":"Could not determine host. The request must have a value provided by the ${header_names}","messagePattern":"Could not determine host\\. The request must have a value provided by the (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-node/src/handler.js","lineNumber":260,"sourceCode":" */\nfunction get_origin(headers) {\n\tconst protocol = decodeURIComponent(\n\t\tnormalise_header(protocol_header, headers[protocol_header]) || 'https'\n\t);\n\n\t// this helps us avoid host injections through the protocol header\n\tif (protocol.includes(':')) {\n\t\tthrow new Error(\n\t\t\t`The ${protocol_header} header specified ${protocol} which is an invalid because it includes \\`:\\`. It should only contain the protocol scheme (e.g. \\`https\\`)`\n\t\t);\n\t}\n\n\tconst host =\n\t\tnormalise_header(host_header, headers[host_header]) ||\n\t\tnormalise_header('host', headers['host']);\n\tif (!host) {\n\t\tconst header_names = host_header ? `${host_header} or host headers` : 'host header';\n\t\tthrow new Error(\n\t\t\t`Could not determine host. The request must have a value provided by the ${header_names}`\n\t\t);\n\t}\n\n\tconst port = normalise_header(port_header, headers[port_header]);\n\tif (port && isNaN(+port)) {\n\t\tthrow new Error(\n\t\t\t`The ${port_header} header specified ${port} which is an invalid port because it is not a number. The value should only contain the port number (e.g. 443)`\n\t\t);\n\t}\n\n\treturn port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;\n}\n\nexport const handler = sequence(\n\t/** @type {(RequestHandler | Middleware)[]} */\n\t([serve(path.join(dir, 'client'), true), serve_prerendered(), ssr].filter(Boolean))\n);","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-node/src/handler.js#L242-L278","documentation":"adapter-node must construct an absolute origin for each request, which requires a host from the configured HOST_HEADER or the standard 'host' header. If neither is present the origin cannot be computed and the request fails. This guards against routing/URL generation breaking silently.","triggerScenarios":"A request without a Host header arrives (HTTP/1.1 requires one; possible with hand-crafted or broken clients), while no alternative HOST_HEADER provides a value.","commonSituations":"Extremely low-level HTTP clients or health checks omitting Host, proxies stripping the Host header, or HTTP/2 requests relying on a :authority mapping your proxy doesn't forward as a host header.","solutions":["Ensure your proxy always sets/forwards a Host header to the Node server","Set PROTOCOL_HEADER/HOST_HEADER (HOST_HEADER env) to a header your infrastructure reliably provides (e.g. x-forwarded-host)","Fix the client sending Host-less requests; per RFC 7230 HTTP/1.1 clients must send Host"],"exampleFix":"// nginx: before\nproxy_pass http://node; # host header dropped\n// after\nproxy_set_header host $host;\nproxy_pass http://node;","handlingStrategy":"validation","validationCode":"if (!req.headers.host && !(process.env.HOST_HEADER && req.headers[process.env.HOST_HEADER.toLowerCase()])) {\n  throw new Error('Request is missing a Host header; cannot determine origin');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await server.respond(request);\n} catch (err) {\n  if (String(err.message).includes('Could not determine host')) {\n    console.error('Ensure proxy forwards Host or set HOST_HEADER to a reliable header');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Always forward Host through the proxy chain (proxy_set_header host $host)","Set HOST_HEADER env to x-forwarded-host when proxies rewrite Host","Reject Host-less requests at the load balancer"],"tags":["http","headers","proxy","configuration"],"backgroundTag":"missing-host-header","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}