cloudflare / vinext

fix: fetch cache key generation — handle all body types, include all headers minus blocklist (#111)
* fix: fetch cache key generation — handle all body types, include all headers minus blocklist - Make buildFetchCacheKey async to support stream/blob body serialization - Handle all BodyInit types: string, Uint8Array, ReadableStream, FormData, Blob, URLSearchParams - Switch header strategy from allowlist (3 auth headers) to blocklist (traceparent/tracestate), matching Next.js - Include RequestInit fields (mode, redirect, credentials, etc.) in cache key - SHA-256 hash the cache key for compact, deterministic storage - Fix spent stream bug: restore _ogBody in stripNextFromInit so originalFetch gets usable body - Add 19 new tests covering body types, header inclusion, body restoration, and URLSearchParams * Improve fetch cache key generation Replace simple auth-header extraction with a unified header collector, add a header blocklist and cache version prefix, and introduce async cache key building. serializeBody now handles various body types (Uint8Array, streams, URLSearchParams, FormData, Blob, string), preserves the original body on init._ogBody, and body content is included in the cache key. The cache key is generated by normalizing URL, method, headers and init options and hashing them with SHA-256. buildFetchCacheKey is now async and awaited where used, and stripNextFromInit restores the preserved original body. Also add hasAuthHeaders and move auth header list into a constant. * PR #111 approved. 52 tests pass, 3 fixes correct. Co-authored-by: threepointone <threepointone@users.noreply.github.com> --------- Co-authored-by: ask-bonk[bot] <ask-bonk[bot]@users.noreply.github.com> Co-authored-by: threepointone <threepointone@users.noreply.github.com>
Sunil Pai Sunil Pai committed on Feb 26, 2026, 12:33 PM
Showing 3 changed files +871 additions -266 deletions
Browse files at this commit →