{"record":{"id":"a80e4e2699205e9b","repo":"denoland/deno","slug":"request-url-protocol-must-be-http-or-https","errorCode":null,"errorMessage":"Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}'","messagePattern":"Request url protocol must be 'http:' or 'https:': received '(.+?)'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cache/01_cache.js","lineNumber":149,"sourceCode":"    request = webidl.converters[\"RequestInfo_DOMString\"](\n      request,\n      prefix,\n      \"Argument 1\",\n    );\n    response = webidl.converters[\"Response\"](response, prefix, \"Argument 2\");\n    // Step 1.\n    let innerRequest = null;\n    // Step 2.\n    if (ObjectPrototypeIsPrototypeOf(RequestPrototype, request)) {\n      innerRequest = toInnerRequest(request);\n    } else {\n      // Step 3.\n      innerRequest = toInnerRequest(new Request(request));\n    }\n    // Step 4.\n    const reqUrl = new URL(innerRequest.url());\n    if (reqUrl.protocol !== \"http:\" && reqUrl.protocol !== \"https:\") {\n      throw new TypeError(\n        `Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}'`,\n      );\n    }\n    if (innerRequest.method !== \"GET\") {\n      throw new TypeError(\"Request method must be GET\");\n    }\n    // Step 5.\n    const innerResponse = toInnerResponse(response);\n    // Step 6.\n    if (innerResponse.status === 206) {\n      throw new TypeError(\"Response status must not be 206\");\n    }\n    // Step 7.\n    const varyHeader = getHeader(innerResponse.headerList, \"vary\");\n    if (varyHeader) {\n      const fieldValues = StringPrototypeSplit(varyHeader, \",\");\n      for (let i = 0; i < fieldValues.length; ++i) {\n        const field = fieldValues[i];","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/cache/01_cache.js#L131-L167","documentation":"Cache.put(request, response) from the Cache API (caches.open(...) in ext/cache/01_cache.js) follows the Service Worker spec steps. Step 4 requires the request URL to be http: or https:, because the HTTP cache only stores network resources - file:, data:, blob:, and other protocols are rejected.","triggerScenarios":"`cache.put(new Request(\"file:///tmp/x\"), res)`; caching a data: or blob: URL; passing a Request whose URL resolved to a non-http protocol.","commonSituations":"Trying to pre-cache local fixture files or data: URLs in tests; offline-first code attempting to cache custom-protocol resources; assuming Cache API works like a generic key-value store.","solutions":["Use an http(s) URL for the cached request","Serve local/test data over http (e.g. a localhost server) before caching it","For non-network resources, use your own storage (KV, IndexedDB) instead of the Cache API"],"exampleFix":"// before\nawait cache.put(new Request(\"file:///tmp/data.json\"), res);\n\n// after\nawait cache.put(new Request(\"http://localhost:8080/data.json\"), res);","handlingStrategy":"validation","validationCode":"function isCacheableUrl(input: RequestInfo | URL): boolean {\n  const protocol = new URL(input instanceof Request ? input.url : input).protocol;\n  return protocol === \"http:\" || protocol === \"https:\";\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the URL protocol before cache.put","Serve local/test fixtures over http instead of file:// or data: URLs","Use KV or IndexedDB for non-http resources"],"tags":["cache-api","cachestorage","url","validation"],"backgroundTag":"invalid-url-protocol","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"}