api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 877 forks source link

Is it possible to have the Content-Location for GetCollections? #6625

Closed darkweak closed 3 weeks ago

darkweak commented 1 month ago

Description

Hello, I dunno if that's possible to return the header Content-Location with the resource location on GetCollection results.

Context: In Souin/cache-handler caddy module we have the tag-based invalidation but we use the Content-Location HTTP response header to generate an associative array with the given format.

[Content-Location header value] => [{Generated cache key from the caddy module for req1}, {Generated cache key from the caddy module for req2}]

Example:

{
    "/books/1": ["GET-http-localhost-/books/1{VARY}content-type:application/xml", "GET-http-localhost-/books/1", "GET-http-localhost-/books/1{VARY}content-type:application/json"]
}

Actually I'm using a kind of hack in the Caddyfile to always have a Content-Location returned by the application with the following snippet:

    vars initialRequest {uri}
    header Content-Location {http.vars.initialRequest}

So it fixes the GetCollection Content-Location issue but generates an additional Content-Location value on GetItem. I know that caddy allows to defer the headers responses but if I use the defer, the middleware doesn't get this header.

Example