Mailing List Archive

synth response body not working…
Within my vcl_recv, I have something like this:


# Allow purging
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return (synth(403, "Forbidden"));
}

if (req.http.xkey-purge) {
set req.http.n-gone = xkey.purge(req.http.xkey-purge);
# If you got this stage (and didn't error out above), purge the cached result
return (synth(200, "Invalidated "+req.http.n-gone+" objects"));
} else {
return (purge);
}

}

…and a a vcl_synth like:

sub vcl_synth {
if (resp.status == 720) {
# We use this special error status 720 to force redirects with 301 (permanent) redirects
# To use this, call the following from anywhere in vcl_recv: return (synth(720, "http://host/new.html"));
set resp.http.Location = resp.reason;
set resp.status = 301;
return (deliver);
} elseif (resp.status == 721) {
# And we use error status 721 to force redirects with a 302 (temporary) redirect
# To use this, call the following from anywhere in vcl_recv: return (synth(720, "http://host/new.html"));
set resp.http.Location = resp.reason;
set resp.status = 302;
return (deliver);
}

return (deliver);
}


When I perform the xkey-purge request, I get back a 200, and can confirm that the purging is working, but the content-length is always 0 (I don't get the "Invalidated n objects" message).

Not sure where to start debugging…any idea what could cause this?


Tim Kelty
Re: synth response body not working… [ In reply to ]
because you return deliver, you are bypassing the builtin.vcl section that
usually calls synthetic() (
https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl#L113),
that is why you have a 0-length body.

Also, the "Invalidated..." message is the reason (like the "OK" for a 200),
not the body. Check the response line of your response (i.e. the first
line, before the headers)

--
Guillaume Quintard


On Thu, Aug 29, 2019 at 11:38 AM Tim Kelty <timkelty@gmail.com> wrote:

> Within my vcl_recv, I have something like this:
>
>
> # Allow purging
> if (req.method == "PURGE") {
> if (!client.ip ~ purge) {
> return (synth(403, "Forbidden"));
> }
>
> if (req.http.xkey-purge) {
> set req.http.n-gone = xkey.purge(req.http.xkey-purge);
> # If you got this stage (and didn't error out above), purge the cached
> result
> return (synth(200, "Invalidated "+req.http.n-gone+" objects"));
> } else {
> return (purge);
> }
>
> }
>
> …and a a vcl_synth like:
>
> sub vcl_synth {
> if (resp.status == 720) {
> # We use this special error status 720 to force redirects with 301
> (permanent) redirects
> # To use this, call the following from anywhere in vcl_recv: return
> (synth(720, "http://host/new.html"));
> set resp.http.Location = resp.reason;
> set resp.status = 301;
> return (deliver);
> } elseif (resp.status == 721) {
> # And we use error status 721 to force redirects with a 302 (temporary)
> redirect
> # To use this, call the following from anywhere in vcl_recv: return
> (synth(720, "http://host/new.html"));
> set resp.http.Location = resp.reason;
> set resp.status = 302;
> return (deliver);
> }
>
> return (deliver);
> }
>
>
> When I perform the xkey-purge request, I get back a 200, and can confirm
> that the purging is working, but the content-length is always 0 (I don't
> get the "Invalidated n objects" message).
>
> Not sure where to start debugging…any idea what could cause this?
>
> —
> Tim Kelty
> _______________________________________________
> varnish-misc mailing list
> varnish-misc@varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
Re: synth response body not working… [ In reply to ]
please keep the mailing-list in the loop

--
Guillaume Quintard


On Tue, Sep 3, 2019 at 2:51 PM Tim Kelty <timkelty@gmail.com> wrote:

> Thanks Guillaume,
>
> Makes sense about bypassing the built-in synth…and the 0-length body.
> Looking at the first line of the response, I can see something like this
> (still no reason after 200):
>
> ? curl -I -X "PURGE" -H "XKEY-PURGE:el30" https://site.com
> HTTP/2 200
> accept-ranges: bytes
> date: Tue, 03 Sep 2019 12:33:14 GMT
> server: Varnish
> x-varnish: 721122
> content-length: 0
>
>
> So what should I return to include the reason in the response?
> I think my vcl_synth example came from:
> https://github.com/mattiasgeniar/varnish-5.0-configuration-templates/blob/master/default.vcl#L381-L397
>
> Thanks again for the help!
>
> —
> Tim Kelty
> On Aug 29, 2019, 3:18 PM -0400, Guillaume Quintard <
> guillaume@varnish-software.com>, wrote:
>
> because you return deliver, you are bypassing the builtin.vcl section that
> usually calls synthetic() (
> https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl#L113),
> that is why you have a 0-length body.
>
> Also, the "Invalidated..." message is the reason (like the "OK" for a
> 200), not the body. Check the response line of your response (i.e. the
> first line, before the headers)
>
> --
> Guillaume Quintard
>
>
> On Thu, Aug 29, 2019 at 11:38 AM Tim Kelty <timkelty@gmail.com> wrote:
>
> Within my vcl_recv, I have something like this:
>
>
> # Allow purging
> if (req.method == "PURGE") {
> if (!client.ip ~ purge) {
> return (synth(403, "Forbidden"));
> }
>
> if (req.http.xkey-purge) {
> set req.http.n-gone = xkey.purge(req.http.xkey-purge);
> # If you got this stage (and didn't error out above), purge the cached
> result
> return (synth(200, "Invalidated "+req.http.n-gone+" objects"));
> } else {
> return (purge);
> }
>
> }
>
> …and a a vcl_synth like:
>
> sub vcl_synth {
> if (resp.status == 720) {
> # We use this special error status 720 to force redirects with 301
> (permanent) redirects
> # To use this, call the following from anywhere in vcl_recv: return
> (synth(720, "http://host/new.html"));
> set resp.http.Location = resp.reason;
> set resp.status = 301;
> return (deliver);
> } elseif (resp.status == 721) {
> # And we use error status 721 to force redirects with a 302 (temporary)
> redirect
> # To use this, call the following from anywhere in vcl_recv: return
> (synth(720, "http://host/new.html"));
> set resp.http.Location = resp.reason;
> set resp.status = 302;
> return (deliver);
> }
>
> return (deliver);
> }
>
>
> When I perform the xkey-purge request, I get back a 200, and can confirm
> that the purging is working, but the content-length is always 0 (I don't
> get the "Invalidated n objects" message).
>
> Not sure where to start debugging…any idea what could cause this?
>
> —
> Tim Kelty
> _______________________________________________
> varnish-misc mailing list
> varnish-misc@varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
>