{"record":{"id":"78dc6d3892c6c0c7","repo":"denoland/deno","slug":"request-method-must-be-get","errorCode":null,"errorMessage":"Request method must be GET","messagePattern":"Request method must be GET","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/cache/01_cache.js","lineNumber":154,"sourceCode":"    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];\n        if (StringPrototypeTrim(field) === \"*\") {\n          throw new TypeError(\"Vary header must not contain '*'\");\n        }\n      }\n    }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/cache/01_cache.js#L136-L172","documentation":"Cache.put(request, response) only accepts GET requests: after the URL protocol check, the implementation rejects any request whose method is not GET. This mirrors the spec rule that only GET requests can be stored in the HTTP cache.","triggerScenarios":"`cache.put(new Request(url, { method: \"POST\" }), res)`; reusing a Request object previously created with method PUT/PATCH/HEAD/DELETE and passing it to cache.put.","commonSituations":"Caching API POST results for offline mode; accidentally reusing a mutated Request; porting code from a generic cache that accepted any method.","solutions":["Construct the cache key as a GET request: `cache.put(new Request(url), res)`","Store POST/PUT responses in your own storage (KV, IndexedDB) rather than the Cache API","Check `request.method === \"GET\"` before calling cache.put when the Request comes from elsewhere"],"exampleFix":"// before\nawait cache.put(new Request(url, { method: \"POST\" }), res);\n\n// after\nawait cache.put(new Request(url), res); // GET key; body lives in res","handlingStrategy":"validation","validationCode":"if (request.method !== \"GET\") {\n  // store POST/PUT results elsewhere; only GET is cacheable\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build cache keys with new Request(url) (defaults to GET)","Check request.method before cache.put when the Request comes from elsewhere","Keep a separate storage path for non-GET API results"],"tags":["cache-api","http-method","validation"],"backgroundTag":"invalid-http-method","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"}