Skip to content

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

Closed

Description

@zdm

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

Activity

  1. added
    bugSomething isn't working
    on Nov 29, 2024
  2. mcollina commented on Nov 29, 2024

    @mcollina
    SponsorMember

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

  3. zdm commented on Nov 30, 2024

    @zdm
    Author
    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.
  4. mcollina commented on Nov 30, 2024

    @mcollina
    SponsorMember

    Ah right, thanks!

  5. ronag commented on Nov 30, 2024

    @ronag
    Member

    @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.

  6. metcoder95 commented on Dec 1, 2024

    @metcoder95
    Member

    Cannot be done on the DispatcherBase#dispatch directly?

  7. added a commit that references this issue on Apr 1, 2025
    ffb7934
  8. added a commit that references this issue on Apr 23, 2025
    fe7aa83
  9. added a commit that references this issue on Apr 24, 2025
    3d3c5cc
  10. added a commit that references this issue on Feb 14, 2026
    1b4f998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions