Giter VIP home page Giter VIP logo

Comments (9)

mholt avatar mholt commented on August 21, 2024 2

@ishuvalov Got it, thanks. I will defer to @darkweak on this.

(FYI, HTTP header Pragma is obsolete HTTP/1.0, and most servers these days won't support it. You should use Cache-Control instead.)

from cache-handler.

ishuvalov avatar ishuvalov commented on August 21, 2024 1

Here is my config. (I find YAML more human friendly than JSON)

apps:
  http:
    servers:
      srv_cache_api:
        listen:
          - :2020
        routes:
          - match:
              - path:
                  - /cache-api*
            handle:
              - handler: cache
      srv_main:
        listen:
          - :80
        automatic_https:
          disable: true
          disable_redirects: true
        routes:
          - handle:
            - handler: cache
            - handler: encode
              encodings:
                gzip: {}
                zstd: {}
              prefer:
                - zstd
                - gzip
            - handler: reverse_proxy
              upstreams:
                - dial: "#{$UPSTREAM}"
        logs:
          default_logger_name: log0

  cache:
    TTL: 1m
    stale: 1m
    log_level: INFO
    api:
      basepath: /cache-api
      souin:
        basepath: /souin
        enable: true
      prometheus:
        basepath: /prometheus
        enable: true

logging:
  logs:
    default:
      writer:
        output: stdout
      level: INFO
      exclude:
        - http.log.access.log0
    error_log:
      writer:
        output: stderr
      level: ERROR
    access:
      writer:
        filename: /var/log/caddy/access.log
        output: file
      level: INFO
      include:
        - http.log.access.log0
admin:
  listen: 0.0.0.0:2019

I also would like to mention, that I tried do build Caddy with two variants of plugin:
xcaddy build --with github.com/caddyserver/cache-handler - this one always returns 200 when missing the upstream, even ignoring "Pragma: no-cache" header
xcaddy build --with github.com/darkweak/souin/plugins/caddy - this returns statuses like in examples I've posted above.

I hope this helps. Thanks.

from cache-handler.

ishuvalov avatar ishuvalov commented on August 21, 2024 1

Works like a charm. Thanks again! 👏

from cache-handler.

mholt avatar mholt commented on August 21, 2024

That sounds like Caddy's default response. Chances are a misconfiguration... What is your config and what is a curl -v command that reproduces the 200 response?

(Then again, it could also very well be a bug in the cache handler. 🤷‍♂️)

from cache-handler.

ishuvalov avatar ishuvalov commented on August 21, 2024

Thank you for the reply.
If I remove cache handler from the handlers chain, I get normal 502 from missing upstream.
A also experimented with curl:

$ curl -v http://localhost/
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Caddy
< Date: Mon, 21 Mar 2022 15:16:21 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact

And doing this way I get proper 502.

$ curl -v -H "Pragma: no-cache"  http://localhost/
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.79.1
> Accept: */*
> Pragma: no-cache
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 502 Bad Gateway
< Cache-Status: Souin; fwd=uri-miss
< Server: Caddy
< Date: Mon, 21 Mar 2022 15:19:09 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact

from cache-handler.

mholt avatar mholt commented on August 21, 2024

Ok, thanks. But what is your config?

from cache-handler.

darkweak avatar darkweak commented on August 21, 2024

The linked PR should fix that directly on Souin.

from cache-handler.

ishuvalov avatar ishuvalov commented on August 21, 2024

Thank you very much! 🙏

from cache-handler.

darkweak avatar darkweak commented on August 21, 2024

@ishuvalov you can use xcaddy build --with github.com/darkweak/souin/plugins/caddy@master or xcaddy build --with github.com/darkweak/souin/plugins/caddy@latest to see the working fix 😉

from cache-handler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.