Ipstenu / varnish-http-purge

Proxy Cache Purge
Apache License 2.0
46 stars 47 forks source link

Varnish 4 #22

Closed joeldavuk closed 7 years ago

joeldavuk commented 8 years ago

Using V4, purging with a regex does not work, don't know if this was previously available?

I notice BAN is also available in 3.0 so it may be better to switch to this method for backwards compatibility, the below works for v4 as it accepts regex.

https://github.com/joeldavuk/varnish-http-purge/commit/379c11cd56aa6d1e24f300e9e11a9597d3a7d920

Ipstenu commented 8 years ago

The plugin doesn't support 4 yet, only 2 and 3.

Also you should submit that as a pull request :)

Ipstenu commented 8 years ago

Looking at #23 that won't work.

'X-Purge-Method' => $varnish_x_purgemethod is not the same as 'method = PURGE' - They're not interchangeable.

But also per https://www.varnish-cache.org/docs/4.1/users-guide/purging.html it appears that HTTP PURGEing is still in use, which is what we're doing here.

Everyone on 3 would have to add this as a custom VCL or rule, and we can't know for sure :/

sub vcl_recv {
        if (req.request == "BAN") {
                # Same ACL check as above:
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                ban("req.http.host == " + req.http.host +
                      " && req.url == " + req.url);

                # Throw a synthetic page so the
                # request won't go to the backend.
                error 200 "Ban added";
        }
}

Also it looks like not everyone in 4 would have this either. That's why the X-Purge-Method exists though. That means you could edit your PURGE to this example: https://github.com/aaemnnosttv/varnish-vcl-collection/blob/5830257b956be56224f6ac676a7bd58b04ab7593/lib/purge.vcl

And that would handle the regex.