{"id":"6ad997c45bf292af","repo":"sindresorhus/got","slug":"url-protocol-must-be-followed-by","errorCode":null,"errorMessage":"`url` protocol must be followed by `//`","messagePattern":"`url` protocol must be followed by `//`","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/core/options.ts","lineNumber":2116,"sourceCode":"\n\t\tif (value === undefined) {\n\t\t\tthis.#internals.url = undefined;\n\t\t\ttrackStateMutation(this.#trackedStateMutations, 'url');\n\t\t\treturn;\n\t\t}\n\n\t\tif (is.string(value) && value.startsWith('/')) {\n\t\t\tthrow new Error('`url` must not start with a slash');\n\t\t}\n\n\t\tconst valueString = value.toString();\n\n\t\tif (\n\t\t\tis.string(value)\n\t\t\t&& !this.prefixUrl\n\t\t\t&& hasHttpProtocolWithoutSlashes(valueString)\n\t\t) {\n\t\t\tthrow new Error('`url` protocol must be followed by `//`');\n\t\t}\n\n\t\t// Detect if URL is already absolute.\n\t\tconst isAbsolute = isAbsoluteUrl(value);\n\t\tassertRelativeUrlIfNeeded(this, value);\n\n\t\t// Only concatenate prefixUrl if the URL is relative\n\t\tconst urlString = isAbsolute ? valueString : `${this.prefixUrl as string}${valueString}`;\n\t\tconst url = new URL(urlString);\n\t\tthis.#internals.url = url;\n\t\ttrackStateMutation(this.#trackedStateMutations, 'url');\n\n\t\tif (usesUnixSocket(url) && !this.#internals.enableUnixSockets) {\n\t\t\tthrow new Error('Using UNIX domain sockets but option `enableUnixSockets` is not enabled');\n\t\t}\n\n\t\tif (url.protocol === 'unix:') {\n\t\t\turl.href = `http://unix${url.pathname}${url.search}`;","sourceCodeStart":2098,"sourceCodeEnd":2134,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/options.ts#L2098-L2134","documentation":"Thrown by the `url` setter when the URL string looks like an HTTP(S) protocol but is not followed by `//` (matched by `/^https?:(?!\\/\\/)/`). Got requires well-formed `http://`/`https://` URLs; a value like `http:example.com` is ambiguous and would be mis-parsed, so it is rejected up front.","triggerScenarios":"Calling `got('http:example.com')`, `got('https:/example.com')` (single slash), or any string matching `http:` or `https:` not immediately followed by `//`. Only fires when there is no `prefixUrl` (with a prefixUrl the value is treated as relative and concatenated).","commonSituations":"Constructing URLs by string concatenation that drops a slash (`'http:' + host`); copy-paste artifacts; config values that were trimmed or lowercased incorrectly.","solutions":["Use a fully-formed URL: `got('http://example.com')`.","If building programmatically, ensure the separator is `://`.","Set a `prefixUrl` if you intend the value to be a relative path."],"exampleFix":"// before\nawait got('http:example.com/api');\n// after\nawait got('http://example.com/api');","handlingStrategy":"validation","validationCode":"function assertWellFormedUrl(url) {\n  if (typeof url === 'string' && /^https?:([^/]|$)/i.test(url) && !/^https?:\\/\\//i.test(url)) {\n    throw new Error(`URL protocol must be followed by '//': ${url}`);\n  }\n}","typeGuard":"function isWellFormedAbsoluteUrl(v: unknown): boolean {\n  return typeof v === 'string' && /^https?:\\/\\//i.test(v);\n}","tryCatchPattern":null,"preventionTips":["Always use `://` when constructing URLs by concatenation.","Prefer `new URL(base, host).href` to build URLs safely.","Add a test that fixtures exercise full `http://` URLs."],"tags":["options","url","validation","parsing"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}