{"id":"37032dc25a764d7b","repo":"sindresorhus/got","slug":"protocol-this-protocol-not-supported-expecte","errorCode":null,"errorMessage":"Protocol \"${this.protocol}\" not supported. Expected \"https:\"","messagePattern":"Protocol \"(.+?)\" not supported\\. Expected \"https:\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/core/utils/http2-client.ts","lineNumber":1048,"sourceCode":"}\n\nclass Http2ClientRequest extends Writable {\n\tconstructor(input: string | URL | NormalizedRequestOptions, options?: NormalizedRequestOptions | RequestCallback, callback?: RequestCallback) {\n\t\tsuper({\n\t\t\tautoDestroy: false,\n\t\t\temitClose: false,\n\t\t});\n\n\t\tconst normalized = normalizeInput(input, options, callback);\n\t\tthis.options = normalized.options;\n\t\tthis.callback = normalized.callback;\n\t\tthis.method = (this.options.method ?? 'GET').toUpperCase();\n\t\tthis.path = this.method === HTTP2_METHOD_CONNECT ? String(this.options.path ?? '') : String(this.options.path ?? '/');\n\t\tthis.protocol = String(this.options.protocol ?? 'https:');\n\t\tthis.headers = Object.create(null) as RequestHeaders;\n\n\t\tif (this.protocol !== 'https:' && !this.options.h2session) {\n\t\t\tthrow new Error(`Protocol \"${this.protocol}\" not supported. Expected \"https:\"`);\n\t\t}\n\n\t\tconst headers = this.options.headers as RequestHeaders | undefined;\n\n\t\tif (headers) {\n\t\t\tfor (const [key, value] of Object.entries(headers)) {\n\t\t\t\tthis.setHeader(key, value);\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.auth && !this.hasHeader('authorization')) {\n\t\t\tthis.setHeader('authorization', `Basic ${Buffer.from(this.options.auth).toString('base64')}`);\n\t\t}\n\n\t\tif (this.callback) {\n\t\t\tthis.once('response', this.callback);\n\t\t}\n","sourceCodeStart":1030,"sourceCodeEnd":1066,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/utils/http2-client.ts#L1030-L1066","documentation":"Http2ClientRequest constructor at http2-client.ts:1048 refuses any protocol other than `https:` (unless an `h2session` is being injected, which implies the caller already has a session). HTTP/2 over cleartext (h2c) is not supported for client requests in this implementation; the protocol must be `https:`.","triggerScenarios":"Calling `got('http://example.com', {http2: true})` (cleartext http URL with http2 enabled), passing a `URL` whose `.protocol === 'http:'` to the http2 path, or a config that sets `http2: true` globally but targets an http origin.","commonSituations":"Forgetting that HTTP/2 client support is TLS-only; pointing a default-`http2` instance at a plain-http internal service; misconfigured `prefixUrl` using `http://`; local dev against an http upstream while production is https.","solutions":["Use an `https://` URL when `http2: true` is set.","If you must talk h2c (cleartext), use a dedicated h2c client — Got does not support it.","Scope the `http2: true` default to https-only instances, or branch on the URL protocol before enabling http2.","Verify `prefixUrl` / `url` literals start with `https://` when http2 is on."],"exampleFix":"// before\nawait got('http://api.internal/svc', {http2: true});\n\n// after\nawait got('https://api.internal/svc', {http2: true});","handlingStrategy":"validation","validationCode":"function assertHttp2Compatible(url) {\n  const protocol = new URL(url).protocol;\n  if (protocol !== 'https:') {\n    throw new Error(`HTTP/2 requires https:, got ${protocol}`);\n  }\n}\nassertHttp2Compatible(url);\nawait got(url, {http2: true});","typeGuard":"const isHttpsUrl = (u: string | URL): boolean =>\n  (typeof u === 'string' ? new URL(u).protocol : u.protocol) === 'https:';","tryCatchPattern":null,"preventionTips":["Scope `http2: true` defaults to https-only Got instances.","Validate URL protocol before enabling http2 on dynamic URLs.","Keep `prefixUrl` on `https://` when http2 is the default.","Document that h2c (cleartext) is unsupported so callers don't try."],"tags":["http2","protocol","tls"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}