Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache interceptor does not process capitalized Cache-Control header in request #3904

Open
zdm opened this issue Nov 29, 2024 · 5 comments
Open
Labels
bug Something isn't working

Comments

@zdm
Copy link

zdm commented Nov 29, 2024

Bug Description

Cache interceptor does not process Cache-Control: no-store request header if header name is capitalized.

In code we can see that you look for lowercased header name only.

You should convert header names to lowercase before search for cache-control;

Reproducible By

Please. see above.

Expected Behavior

Please. see above.

Logs & Screenshots

Environment

undici v7

Additional context

@zdm zdm added the bug Something isn't working label Nov 29, 2024
@mcollina
Copy link
Member

Can you add a reproduction? It's working correctly here.

@zdm
Copy link
Author

zdm commented Nov 30, 2024

import { Agent, fetch, interceptors } from "undici";

const dispatcher = new Agent().compose( interceptors.cache() );

for ( let n = 0; n < 2; n++ ) {
    const res = await fetch( "https://httpbingo.org/cache/60", {
        dispatcher,
        "headers": {
            "X-Data": new Date().toISOString(),
            "Cache-Control": "no-store",
        },
    } );

    console.log( ( await res.json() ).headers[ "X-Data" ] );
}
  1. You can see, that data not changed - this means, that cached response used.
  2. If you change Cache-Control header to the lower case - cache will be bypassed.

@mcollina
Copy link
Member

Ah right, thanks!

@ronag
Copy link
Member

ronag commented Nov 30, 2024

@mcollina this is related to that "normalizeHeaders" function I was working on that would always normalize the user passed headers. I think we should probably have a "pre-interceptor" that always does this to make things easier down chain.

@metcoder95
Copy link
Member

Cannot be done on the DispatcherBase#dispatch directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants