-
-
Notifications
You must be signed in to change notification settings - Fork 688
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
I was trying to try out undici cache with the following code snippets:
import undici, {
interceptors,
Agent,
setGlobalDispatcher
} from 'undici';
setGlobalDispatcher(agent.compose(
interceptors.cache({
store: new undici.cacheStores.MemoryCacheStore()
})
));
(async () => {
console.time('fetch');
await undici.request('https://easylist.to/easylist/easylist.txt');
console.timeEnd('fetch');
console.time('fetch 2');
await undici.request('https://easylist.to/easylist/easylist.txt');
console.timeEnd('fetch 2');
})();However, I noticed that the request is never cached.
Reproducible By
See code snippet above.
Expected Behavior
The request should be cached and the fetch 2 should happen "instantly".
Environment
Node.js v22.11.0 on Darwin
Additional context
I noticed that https://easylist.to/easylist/easylist.txt is returning the Vary: Accept-Encoding response header regardless of whether Accept-Encoding is included in the request header. This causes undici to panic because undici doesn't expect Accept-Encoding to be included in the cacheKey:
undici/lib/handler/cache-handler.js
Lines 133 to 137 in 2c36442
| varyDirectives = parseVaryHeader(headers.vary, this.#cacheKey.headers) | |
| if (!varyDirectives) { | |
| // Parse error | |
| return downstreamOnHeaders() | |
| } |
cc @flakey5
flakey5
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working