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

Vary header mechanism #868

Closed
basaran opened this issue Apr 8, 2024 · 1 comment
Closed

Vary header mechanism #868

basaran opened this issue Apr 8, 2024 · 1 comment
Labels

Comments

@basaran
Copy link

basaran commented Apr 8, 2024

Environment info:

Version: 2.6.0
Linux 6.7.7-1-MANJARO x86_64

Describe what are you trying to do:
I have a request header which limits the number of records returned from an API. I need to have Krakend pay attention to the Vary header.

To be on the safe side, I added Vary to the allowed headers.

      "allow_headers": [
        "Origin",
        "Authorization",
        "Content-Type",
        "Cache-Control",
        "prefer",
        "Vary"
      ],

I sent my request with the following headers:

Content-Type: application/x-www-form-urlencoded
User-Agent: insomnium/0.2.3-a
Cache-Control: max-age=604800
prefer: maxpagesize=10
Vary: prefer

When I change the value of the maxpagesize, I still hit the same cache. To be on the safe side, I also tried:

Content-Type: application/x-www-form-urlencoded
User-Agent: insomnium/0.2.3-a
Cache-Control: max-age=604800
prefer: maxpagesize=10
Vary: *

According to MDN, the asterisk implies cache should not be returned.

@thedae
Copy link
Member

thedae commented Feb 12, 2025

Hi @basaran , I've been doing some tests and I'm not able to reproduce your case, check this config out in case you've something missing in your setup:

{
  "$schema": "https://krakend.io/schema/krakend.json",
  "version": 3,
  "echo_endpoint": true,
  "endpoints": [
    {
      "endpoint": "/",
      "input_headers": ["prefer"],
      "backend": [
        {
          "host": ["http://localhost:9000"],
          "url_pattern": "/vary-header",
          "extra_config": {
            "qos/http-cache": {}
          }
        }
      ]
    }
  ]
}

The backend is rather simple, just a mock server returning Cache-control and Vary headers:

 curl -i http://localhost:9000/vary-header
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Vary: prefer
Cache-Control: public, max-age=600
Content-Length: 34
Date: Wed, 12 Feb 2025 12:37:06 GMT
Connection: keep-alive
Keep-Alive: timeout=5
...

With the setup above, Krakend cache layer is working as expected: the cache cardinality depends on the prefer header value

Let me know if this helps and feel free to reopen if needed

@thedae thedae closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants