How to cache mail requests with varnish?

I am using docker polish - see million12 / varnish

GET requests work great!

but I don't know what I need to set in the settings for caching POST requests.

on google I found many posts (from 2010 or 2011) where it says that POST requests cannot be cached with varnish - is this statement still true?

Or is there any other way to cache POST requests?

here's the varnish.vcl settings :

vcl 4.0;
backend default {
    ...
}

# Respond to incoming requests.
sub vcl_recv {
  unset req.http.Cookie;
}

# Set a header to track a cache HIT/MISS.
sub vcl_deliver {
  if (obj.hits > 0) {
    set resp.http.X-Varnish-Cache = "HIT";
  }
  else {
    set resp.http.X-Varnish-Cache = "MISS";
  }
}

# Not cache 400 - 500 status requests
sub vcl_backend_response {
    if (beresp.status >= 400 && beresp.status <= 600) {
        set beresp.ttl = 0s;
  }
}

      

Thanks for the help!

+3


source to share


3 answers


Varnish is currently unable to cache POST requests .

AFAIK users try to cache the POST request. It seems like Luck is finishing converting them to GET requests.



Sources:

+5


source


There is a Varnish module and tutorial for caching POST requests. This adds the ability to add the body of the message to the hash key and pass the POST request.

VMOD is available for the Varnish 4 releases and includes the following Features:

buffer_req_body(BYTES size): buffers the request body if it is smaller
    than size. This function is a "better" (bug-free**) copy of
    std.CacheReqBody(), so please use this one instead of the one provided
    by the libvmod-std. Please note that retrieving req.body makes it
    possible to retry pass operations(POST, PUT).

len_req_body(): returns the request body length.

rematch_req_body(STRING re): regular expression match on request body.

hash_req_body(): adds body bytes to the input hash key.

      



https://info.varnish-software.com/blog/caching-post-requests-with-varnish https://github.com/aondio/libvmod-bodyaccess

Note that the 4.1 branch of this VMOD buffer_req_body()

uses inline instead std.cache_req_body()

, but a persistent bug in Varnish 4.1 breaks the 4.1 branch. https://github.com/varnishcache/varnish-cache/issues/1927

+5


source


  • add another ngnx / apache / to the unused port
  • push POST request to this server.
  • there you pass them to varnish as a get request and retrieve the result
  • displaying the result via your repeater

will probably slow things down a bit - but are we talking about dirty workarounds here? Hope it's not too crazy a solution.

0


source







All Articles