Unverified Commit 512cabc1 authored by Jeffrey Zutt's avatar Jeffrey Zutt Committed by GitHub

feat: strip traceparent header from cachekey (#64499)

### What?
We strip the `traceparent` header from the cache-key.

### Why?
The traceparent header forms part of the W3C Trace Context standard,
installed to track individual HTTP requests from start to end across
multiple services. That means each individual HTTP request will have a
unique traceparent value, reflecting its unique journey across servers
and services.

If we include the traceparent header in the cache key, the uniqueness of
the traceparent means the cache key would always be different even for
requests that should yield the same response. This would cause the cache
to always miss and re-process the request.

Effectively rendering fetch-cache useless.
Co-authored-by: 's avatarJeffrey <jeffrey@jeffreyzutt.nl>
parent e7a8645c
...@@ -385,14 +385,19 @@ export class IncrementalCache implements IncrementalCacheType { ...@@ -385,14 +385,19 @@ export class IncrementalCache implements IncrementalCacheType {
} }
} }
const headers =
typeof (init.headers || {}).keys === 'function'
? Object.fromEntries(init.headers as Headers)
: Object.assign(init.headers || {}, {})
if ('traceparent' in headers) delete headers['traceparent']
const cacheString = JSON.stringify([ const cacheString = JSON.stringify([
MAIN_KEY_PREFIX, MAIN_KEY_PREFIX,
this.fetchCacheKeyPrefix || '', this.fetchCacheKeyPrefix || '',
url, url,
init.method, init.method,
typeof (init.headers || {}).keys === 'function' headers,
? Object.fromEntries(init.headers as Headers)
: init.headers,
init.mode, init.mode,
init.redirect, init.redirect,
init.credentials, init.credentials,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment