diff --git a/src/http-api/fetch.ts b/src/http-api/fetch.ts index d6d1b5a52a3..3869145914e 100644 --- a/src/http-api/fetch.ts +++ b/src/http-api/fetch.ts @@ -279,6 +279,13 @@ export class FetchHttpApi { const { signal, cleanup } = anySignal(signals); + // Set cache mode based on presence of Authorization header. + // Browsers/proxies do not cache responses to requests with Authorization headers. + // So specifying "no-cache" is redundant, and actually prevents caching + // of preflight requests in CORS scenarios. As such, we only set "no-cache" + // when there is no Authorization header. + const cacheMode = "Authorization" in headers ? undefined : "no-cache"; + let res: Response; const start = Date.now(); try { @@ -291,7 +298,7 @@ export class FetchHttpApi { redirect: "follow", referrer: "", referrerPolicy: "no-referrer", - cache: "no-cache", + cache: cacheMode, credentials: "omit", // we send credentials via headers keepalive: keepAlive, priority: opts.priority,