darkweak / souin

An HTTP cache system, RFC compliant, compatible with @tyktechnologies, @traefik, @caddyserver, @go-chi, @bnkamalesh, @beego, @devfeel, @labstack, @gofiber, @go-goyave, @go-kratos, @gin-gonic, @roadrunner-server, @zalando, @zeromicro, @nginx and @apache

Home Page:https://docs.souin.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot hide key in Cache-Status response header

yongzhang opened this issue · comments

Hi @darkweak

I'm testing souin v1.6.38 with traefik 2.9.10 today, I have config like this:

experimental:
  localPlugins:
    caching:
      moduleName: github.com/darkweak/souin
----------------
http:
  middlewares:
    http-cache:
      plugin:
        caching:
          default_cache:
            ttl: 5m
            default_cache_control: no-store
            key:
              disable_body: true
              disable_host: false
              disable_method: false
              disable_query: true
              hide: true
          log_level: debug

  routers:
    whoami-cache:
      entryPoints:
        - "web"
      rule: "Host(`whoami.example.com`) && PathPrefix(`/cache`)"
      service: whoami
      middlewares:
        - http-cache

  services:
    whoami:
      loadBalancer:
        servers:
          - url: "http://whoami/"

I got:

*   Trying 127.0.0.1:8080...
> GET /cache HTTP/1.1
> Host: whoami.example.com
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Age: 1
< Cache-Status: Souin; hit; ttl=299; key=GET-http-whoami.example.com-/cache
< Content-Length: 469
< Content-Type: text/plain; charset=utf-8
< Date: Wed, 14 Jun 2023 06:46:07 GMT
< Vary: Accept-Encoding

Caching is working, which is great! But seems like hide: true is not working, any ideas?

And are we able to have simple cache status header something like:

X-Cache-Status: HIT[MISS|...]

Thanks.

Hey @yongzhang thank you for your feedback. I investigated about your issue and the traffic configuration parser is not equal to the actual configuration https://github.com/darkweak/souin/blob/master/plugins/traefik/main.go#L74. The default_cache doesn't try to parse neither the key nor the cache_keys keys. If you have some time to write a fix (just add some cases to the existing code) or can wait few days (because I'm a bit busy now) I could write the fix.

Hey @yongzhang thank you for your feedback. I investigated about your issue and the traffic configuration parser is not equal to the actual configuration https://github.com/darkweak/souin/blob/master/plugins/traefik/main.go#L74. The default_cache doesn't try to parse neither the key nor the cache_keys keys. If you have some time to write a fix (just add some cases to the existing code) or can wait few days (because I'm a bit busy now) I could write the fix.

ahh... yea I can try with a fix, if I can't complete this then I'll ping you again here 😄

@darkweak After looking into the code, I'm a bit confused that, in this place:

https://github.com/darkweak/souin/blob/master/plugins/traefik/main.go#L22-L28

Why it returns TestConfiguration? Why not just use Configuration so traefik will parse input automatically?