{"record":{"id":"6e8bcbb7bc1cc2ef","repo":"denoland/deno","slug":"err-http2-altsvc-invalid-origin","errorCode":"ERR_HTTP2_ALTSVC_INVALID_ORIGIN","errorMessage":"HTTP/2 ALTSVC frames require a valid origin","messagePattern":"HTTP/2 ALTSVC frames require a valid origin","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/http2.ts","lineNumber":4586,"sourceCode":"    return this[kServer];\n  }\n\n  // Submits an altsvc frame to be sent to the client. `stream` is a\n  // numeric Stream ID. origin is a URL string that will be used to get\n  // the origin. alt is a string containing the altsvc details. No fancy\n  // API is provided for that.\n  altsvc(alt, originOrStream) {\n    if (this.destroyed) {\n      throw new ERR_HTTP2_INVALID_SESSION();\n    }\n\n    let stream = 0;\n    let origin;\n\n    if (typeof originOrStream === \"string\") {\n      origin = getURLOrigin(originOrStream);\n      if (origin === \"null\") {\n        throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN();\n      }\n    } else if (typeof originOrStream === \"number\") {\n      if (originOrStream >>> 0 !== originOrStream || originOrStream === 0) {\n        throw new ERR_OUT_OF_RANGE(\n          \"originOrStream\",\n          `> 0 && < ${2 ** 32}`,\n          originOrStream,\n        );\n      }\n      stream = originOrStream;\n    } else if (originOrStream !== undefined) {\n      // Allow origin to be passed a URL or object with origin property\n      if (originOrStream !== null && typeof originOrStream === \"object\") {\n        origin = originOrStream.origin;\n      }\n      // Note: if originOrStream is an object with an origin property other\n      // than a URL, then it is possible that origin will be malformed.\n      // We do not verify that here. Users who go that route need to","sourceCodeStart":4568,"sourceCodeEnd":4604,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/http2.ts#L4568-L4604","documentation":"In altsvc(alt, originOrStream), when originOrStream is a string it is parsed with getURLOrigin(), which returns new URL(str).origin. URLs that have an opaque/undefined origin (origin === \"null\" — e.g. file:, data:, or other non-hierarchical schemes) produce ERR_HTTP2_ALTSVC_INVALID_ORIGIN because an ALTSVC frame needs a concrete serialized origin. Note that a string the URL constructor cannot parse at all throws ERR_INVALID_URL earlier instead.","triggerScenarios":"session.altsvc(alt, 'file:///srv/site'), altsvc(alt, 'data:text/plain,hi'), or any scheme where URL.prototype.origin is the string 'null'.","commonSituations":"Deriving the origin from req.url (a path like '/foo') instead of the Host header or absolute URL; feeding a config value that lost its scheme ('example.com:8443' is unparseable, 'file://' mounts are 'null'); handling non-HTTP origins in a generic adapter.","solutions":["Pass an absolute http/https URL such as 'https://example.com:8443' so URL.origin is concrete","Build the origin from the request's authority: `https://${req.authority}` or `https://${req.headers.host}`","If you only mean a stream, pass the numeric stream ID instead of a URL"],"exampleFix":"// before\nsession.altsvc('h2=\":8443\"', new URL(req.url, 'file:///').href); // origin === 'null'\n\n// after\nsession.altsvc('h2=\":8443\"', `https://${clientSocket.remoteAddress}`);","handlingStrategy":"validation","validationCode":"const origin = new URL(urlString).origin;\nif (origin === 'null') throw new TypeError(`no usable origin in ${urlString}`);\nsession.altsvc(alt, urlString);","typeGuard":"function hasConcreteOrigin(urlString) {\n  try { return new URL(urlString).origin !== 'null'; } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Always pass absolute http/https URLs with scheme and host","Build origins from the request authority/Host header, never from req.url paths","Remember: unparseable strings throw ERR_INVALID_URL, opaque origins (file:, data:) throw this error"],"tags":["http2","node-compat","altsvc","url-parsing"],"backgroundTag":"invalid-url-origin","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}