{"record":{"id":"e2f143cd9e6b80bc","repo":"denoland/deno","slug":"the-url-passed-into-proxy-url-has-an-invalid-sch","errorCode":null,"errorMessage":"The url passed into 'proxy.url' has an invalid scheme for this transport.","messagePattern":"The url passed into 'proxy\\.url' has an invalid scheme for this transport\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/22_http_client.js","lineNumber":42,"sourceCode":"  // Don't mutate the caller's options object. Historically `caCerts` and\n  // `proxy.transport` were written back onto whatever the user passed in,\n  // which broke reuse of a single options object across multiple calls\n  // (denoland/deno#29347).\n  options = ObjectAssign({ __proto__: null }, options);\n  options.caCerts = options.caCerts ?? [];\n  if (options.proxy) {\n    const proxy = ObjectAssign({ __proto__: null }, options.proxy);\n    options.proxy = proxy;\n    if (ObjectHasOwn(proxy, \"transport\")) {\n      switch (proxy.transport) {\n        case \"http\": {\n          const url = proxy.url;\n          if (\n            StringPrototypeStartsWith(url, \"https:\") ||\n            StringPrototypeStartsWith(url, \"socks5:\") ||\n            StringPrototypeStartsWith(url, \"socks5h:\")\n          ) {\n            throw new TypeError(\n              `The url passed into 'proxy.url' has an invalid scheme for this transport.`,\n            );\n          }\n          proxy.transport = \"http\";\n          break;\n        }\n        case \"https\": {\n          const url = proxy.url;\n          if (\n            StringPrototypeStartsWith(url, \"http:\") ||\n            StringPrototypeStartsWith(url, \"socks5:\") ||\n            StringPrototypeStartsWith(url, \"socks5h:\")\n          ) {\n            throw new TypeError(\n              `The url passed into 'proxy.url' has an invalid scheme for this transport.`,\n            );\n          }\n          proxy.transport = \"http\";","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/22_http_client.js#L24-L60","documentation":"Thrown in createHttpClient() (ext/fetch/22_http_client.js) when the proxy configuration declares a transport but proxy.url's scheme belongs to a different transport: for transport \"http\", urls starting with https:, socks5:, or socks5h: are rejected (and symmetrically for \"https\", http:/socks urls). This validates scheme-vs-transport consistency before the client is built.","triggerScenarios":"`Deno.createHttpClient({ proxy: { url: \"https://proxy.example:3128\", transport: \"http\" } })`; also `proxy: { url: \"socks5://h:1080\", transport: \"http\" }`. The string transport form `proxy: { url }` (no transport field) infers from the scheme and does not hit this check.","commonSituations":"Config files where url and transport drift apart after edits (TLS added to proxy but transport left \"http\"); copying an HTTPS proxy URL into a template that hardcodes transport \"http\"; CI environments injecting a corporate HTTPS proxy while code pins transport.","solutions":["Align them: `proxy: { url: \"https://proxy.example:3128\", transport: \"https\" }` for TLS proxies.","Or omit transport and let Deno infer it from the scheme: `proxy: { url: \"http://proxy.example:3128\" }`.","For SOCKS proxies use transport \"socks5\"/\"socks5h\" with a matching socks5:// url."],"exampleFix":"// before\nconst client = Deno.createHttpClient({\n  proxy: { url: \"https://proxy.internal:3128\", transport: \"http\" }, // mismatch\n});\n\n// after\nconst client = Deno.createHttpClient({\n  proxy: { url: \"https://proxy.internal:3128\", transport: \"https\" },\n});","handlingStrategy":"validation","validationCode":"const scheme = new URL(proxyUrl).protocol; // \"https:\", \"socks5:\", ...\nconst transport = scheme.replace(\":\", \"\").replace(\"socks5h\", \"socks5h\");\nconst client = Deno.createHttpClient({ proxy: { url: proxyUrl, transport } }); // or omit transport entirely","typeGuard":null,"tryCatchPattern":"try { Deno.createHttpClient(opts); } catch (e) { if (e instanceof TypeError && e.message.includes(\"invalid scheme for this transport\")) { delete opts.proxy.transport; /* let Deno infer from scheme */ client = Deno.createHttpClient(opts); } else throw e; }","preventionTips":["Derive transport from the URL scheme instead of hardcoding both.","Or specify only proxy.url and let the runtime infer.","Validate proxy config once at startup so bad URLs fail before the first fetch."],"tags":["proxy","http-client","configuration","fetch"],"backgroundTag":"proxy-configuration-error","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}