sillygod / cdp-cache

a caddy 2 proxy cache plugin
MIT License
119 stars 17 forks source link

Can't get POST cache to work #50

Closed eithe closed 2 years ago

eithe commented 2 years ago

@sillygod Thank you so much for creating this package!

I'm struggling to get POST caching to work, it always results in a skip. GET cache does work. The upstream server that I'm proxying only responds with 3 headers (date, content-type, content-length) on both POST and GET request so shouldn't be anything on that side.

Here is my config.

{
    auto_https off
    auto_https disable_redirects
    debug
    order http_cache before reverse_proxy

}

http://api.mysite.com {
    reverse_proxy {
        to localhost:9995
    }

    http_cache {
      cache_key "{http.request.method} {http.request.host}{http.request.uri.path}?{http.request.uri.query} {http.request.contentlength} {http.request.bodyhash}"
      cache_type in_memory
      match_methods POST GET HEAD
    }
}

:9995 {
  header Access-Control-Allow-Methods "POST, GET, OPTIONS, PUT"
  header Access-Control-Allow-Headers "*"
  header Access-Control-Allow-Origin "https://mysite.com"
  header Cache-control "public"

  reverse_proxy https://api.anothersite.com {
    header_up Host api.anothersite.com
  }
}

I'm using the docker.pkg.github.com/sillygod/cdp-cache/caddy:latest image.

Any tips?

sillygod commented 2 years ago

Hi @eithe , I am glad you like it!

It's a little bit hard to know what causes the cache status to be skip. Could you please provide more information in detail ?

For example , the request header, the reponse header .

I think the key point is the response from the https://api.anothersite.com . Maybe you can inspect the reponse headers.

eithe commented 2 years ago

Hi @sillygod and thanks for your reply. Sorry for not coming back to you earlier, but the request in question is a POST to https://api.turfgame.com/private/users with a json body of [{"name":"ZonerX"}].

The response headers are actually only date, content-type, vary.

However, on further thinking and since I couldn't figure out how I was using caddy and/or your package incorrectly, I landed on using Varnish cache as I really only needed a quick proxy with some caching for this little side project.