denoland/deno · error · TypeError
Request url protocol must be 'http:' or 'https:': received
Error message
Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}' What it means
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.
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
Example fix
// before
await cache.put(new Request("file:///tmp/data.json"), res);
// after
await cache.put(new Request("http://localhost:8080/data.json"), res); Defensive patterns
Strategy: validation
Validate before calling
function isCacheableUrl(input: RequestInfo | URL): boolean {
const protocol = new URL(input instanceof Request ? input.url : input).protocol;
return protocol === "http:" || protocol === "https:";
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- ERR_INVALID_URL
- Invalid URL: ' ' with base
- package name contains a URL path or delimiter character
- Request method must be GET
- SyntaxError
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/a80e4e2699205e9b.
Report an issue: GitHub.
Appendix: source
Thrown at ext/cache/01_cache.js:149
request = webidl.converters["RequestInfo_DOMString"](
request,
prefix,
"Argument 1",
);
response = webidl.converters["Response"](response, prefix, "Argument 2");
// Step 1.
let innerRequest = null;
// Step 2.
if (ObjectPrototypeIsPrototypeOf(RequestPrototype, request)) {
innerRequest = toInnerRequest(request);
} else {
// Step 3.
innerRequest = toInnerRequest(new Request(request));
}
// Step 4.
const reqUrl = new URL(innerRequest.url());
if (reqUrl.protocol !== "http:" && reqUrl.protocol !== "https:") {
throw new TypeError(
`Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}'`,
);
}
if (innerRequest.method !== "GET") {
throw new TypeError("Request method must be GET");
}
// Step 5.
const innerResponse = toInnerResponse(response);
// Step 6.
if (innerResponse.status === 206) {
throw new TypeError("Response status must not be 206");
}
// Step 7.
const varyHeader = getHeader(innerResponse.headerList, "vary");
if (varyHeader) {
const fieldValues = StringPrototypeSplit(varyHeader, ",");
for (let i = 0; i < fieldValues.length; ++i) {
const field = fieldValues[i];View on GitHub (pinned to 9ad36f7a2c)