ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
4.96k stars 722 forks source link

HotChocolate.Caching outputs max-age header in milliseconds instead of seconds #7053

Closed kiangkuang closed 1 month ago

kiangkuang commented 1 month ago

Product

Hot Chocolate

Version

13.8.1

Link to minimal reproduction

https://github.com/kiangkuang/HotChocolateDemo

Steps to reproduce

  1. Clone this project that has been minimally configured like in https://www.youtube.com/watch?v=sk4XD3Zf64k
  2. Run the project and execute the query
    query {
        book {
            title
        }
    }

What is expected?

Response with header Cache-Control: public, max-age=10, because the units for max-age should be in seconds instead of milliseconds.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#response_directives https://developers.cloudflare.com/cache/concepts/cache-control/

What is actually happening?

Response with header Cache-Control: public, max-age=10000, which was the milliseconds value specified in code.

Relevant log output

No response

Additional context

image image

I'm not sure whether the better fix should either be to

  1. Change the parameter units to be in Seconds or
  2. Do the conversion from Milliseconds to Seconds when outputting the header, which has the ambiguity of whether CDNs or browsers expect non-integer values like max-age=10.5 which arises due to the unit conversion.
tobias-tengler commented 1 month ago

This is an issue with the XML documentation. If you want to, you can raise a PR that corrects the descriptions. The code resides in src/HotChocolate/Caching/src/Caching :)