[prev in list] [next in list] [prev in thread] [next in thread] 

List:       varnish-misc
Subject:    =?UTF-8?Q?Re=3A_synth_response_body_not_working=E2=80=A6?=
From:       Guillaume Quintard <guillaume () varnish-software ! com>
Date:       2019-09-09 6:27:31
Message-ID: CAJ6ZYQycoqhdLz0TvxTPzj6WmFaWwMckVY5LOT2Q0G+CqaWp2Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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
>
>

[Attachment #5 (text/html)]

<div dir="ltr">please keep the mailing-list in the loop<div><br clear="all"><div><div \
dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div \
dir="ltr"><div>-- <br></div>Guillaume \
Quintard<br></div></div></div><br></div></div><br><div class="gmail_quote"><div \
dir="ltr" class="gmail_attr">On Tue, Sep 3, 2019 at 2:51 PM Tim Kelty &lt;<a \
href="mailto:timkelty@gmail.com">timkelty@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div>
<div name="messageBodySection">
<div dir="auto">Thanks  <span style="color:rgb(9,20,57);font-family:&quot;Helvetica \
Neue&quot;">Guillaume,</span> <div dir="auto"><br></div>
<div dir="auto">Makes sense about bypassing the built-in synth…and the 0-length \
body.</div> <div dir="auto">Looking at the first line of the response, I can see \
something like this (still no reason after 200):</div> <div dir="auto"><br></div>
<blockquote style="margin:5px;padding-left:10px;border-left:thin solid \
rgb(26,188,156)" class="gmail-m_7098675303203673720spark_quote"> <div dir="auto">❯ \
curl -I -X &quot;PURGE&quot; -H &quot;XKEY-PURGE:el30&quot; <a \
href="https://site.com" target="_blank">https://site.com</a></div> <div \
dir="auto">HTTP/2 200</div> <div dir="auto">accept-ranges: bytes</div>
<div dir="auto">date: Tue, 03 Sep 2019 12:33:14 GMT</div>
<div dir="auto">server: Varnish</div>
<div dir="auto">x-varnish: 721122</div>
<div dir="auto">content-length: 0</div>
</blockquote>
<div dir="auto"><br></div>
<div dir="auto">So what should I return to include the reason in the response?</div>
<div dir="auto">I think my vcl_synth example came from:  <a \
href="https://github.com/mattiasgeniar/varnish-5.0-configuration-templates/blob/master/default.vcl#L381-L397" \
target="_blank">https://github.com/mattiasgeniar/varnish-5.0-configuration-templates/blob/master/default.vcl#L381-L397</a></div>
 <div dir="auto"><br></div>
<div dir="auto">Thanks again for the help!</div>
</div>
</div>
<div name="messageSignatureSection"><br>
<div class="gmail-m_7098675303203673720matchFont">—<br>
Tim Kelty<br></div>
</div>
<div name="messageReplySection">On Aug 29, 2019, 3:18 PM -0400, Guillaume Quintard \
&lt;<a href="mailto:guillaume@varnish-software.com" \
target="_blank">guillaume@varnish-software.com</a>&gt;, wrote:<br> <blockquote \
type="cite" class="gmail-m_7098675303203673720spark_quote" \
style="margin:5px;padding-left:10px;border-left:thin solid rgb(26,188,156)"> <div \
dir="ltr">because you return deliver, you are bypassing the builtin.vcl section that \
usually calls synthetic() (<a \
href="https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl#L113" \
target="_blank">https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishd/builtin.vcl#L113</a>), \
that is why you have a 0-length body. <div><br></div>
<div>Also, the &quot;Invalidated...&quot; message is the reason (like the \
&quot;OK&quot; for a 200), not the body. Check the response line of your response \
(i.e. the first line, before the headers)</div> <div><br clear="all">
<div>
<div dir="ltr" class="gmail-m_7098675303203673720gmail_signature">
<div dir="ltr">
<div>--<br></div>
Guillaume Quintard<br></div>
</div>
</div>
<br></div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, Aug 29, 2019 at 11:38 AM Tim Kelty &lt;<a \
href="mailto:timkelty@gmail.com" target="_blank">timkelty@gmail.com</a>&gt; \
wrote:<br></div> <blockquote class="gmail_quote \
gmail-m_7098675303203673720spark_quote" \
style="margin:5px;padding-left:10px;border-left:thin solid rgb(230,126,34)"> <div>
<div name="messageBodySection">
<div dir="auto">Within my vcl_recv, I have something like this:
<div dir="auto"><br></div>
<div dir="auto"><br></div>
<div dir="auto">
<div style="color:rgb(204,204,204);background-color:rgb(45,45,45);font-size:18px;line-height:27px;white-space:pre-wrap">
 <div><span style="color:rgb(153,153,153)"># Allow purging</span></div>
<div><span style="color:rgb(204,153,204)">if</span> (<span \
style="color:rgb(242,119,122)">req.method</span> == <span \
style="color:rgb(153,204,153)">&quot;PURGE&quot;</span>) {</div> <div><span \
style="color:rgb(204,153,204)">if</span> (!<span \
style="color:rgb(242,119,122)">client.ip</span> ~ <span \
style="color:rgb(102,153,204)">purge</span>) {</div> <div><span \
style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">synth</span>(403, &quot;Forbidden&quot;));</div> \
<div>}</div> <br>
<div><span style="color:rgb(204,153,204)">if</span> (<span \
style="color:rgb(242,119,122)">req.http.xkey-purge</span>) {</div> <div><span \
style="color:rgb(204,153,204)">set</span> <span \
style="color:rgb(242,119,122)">req.http.n-gone</span> = xkey.<span \
style="color:rgb(102,153,204)">purge</span>(<span \
style="color:rgb(242,119,122)">req.http.xkey-purge</span>);</div> <div><span \
style="color:rgb(153,153,153)"># If you got this stage (and didn&#39;t error out \
above), purge the cached result</span></div> <div><span \
style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">synth</span>(200, &quot;Invalidated \
&quot;+req.http.n-gone+&quot; objects&quot;));</div> <div>} <span \
style="color:rgb(204,153,204)">else</span> {</div> <div><span \
style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">purge</span>);</div> <div>}</div>
<br>
<div>}</div>
</div>
</div>
</div>
</div>
<div name="messageSignatureSection"><br>
<div class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto">…and a a vcl_synth like:</div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto"><br></div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" dir="auto"> \
<div style="color:rgb(204,204,204);background-color:rgb(45,45,45);line-height:27px;white-space:pre-wrap">
 <div><span style="color:rgb(204,153,204)">sub</span> vcl_synth {</div>
<div><span style="color:rgb(204,153,204)">if</span> (<span \
style="color:rgb(242,119,122)">resp.status</span> == <span \
style="color:rgb(249,145,87)">720</span>) {</div> <div><span \
style="color:rgb(153,153,153)"># We use this special error status 720 to force \
redirects with 301 (permanent) redirects</span></div> <div><span \
style="color:rgb(153,153,153)"># To use this, call the following from anywhere in \
vcl_recv: return (synth(720, &quot;<a href="http://host/new.html" \
target="_blank">http://host/new.html</a>&quot;));</span></div> <div><span \
style="color:rgb(204,153,204)">set</span> <span \
style="color:rgb(242,119,122)">resp.http.Location</span> = <span \
style="color:rgb(242,119,122)">resp.reason</span>;</div> <div><span \
style="color:rgb(204,153,204)">set</span> <span \
style="color:rgb(242,119,122)">resp.status</span> = <span \
style="color:rgb(249,145,87)">301</span>;</div> <div><span \
style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">deliver</span>);</div> <div>} <span \
style="color:rgb(204,153,204)">elseif</span> (<span \
style="color:rgb(242,119,122)">resp.status</span> == <span \
style="color:rgb(249,145,87)">721</span>) {</div> <div><span \
style="color:rgb(153,153,153)"># And we use error status 721 to force redirects with \
a 302 (temporary) redirect</span></div> <div><span style="color:rgb(153,153,153)"># \
To use this, call the following from anywhere in vcl_recv: return (synth(720, \
&quot;<a href="http://host/new.html" \
target="_blank">http://host/new.html</a>&quot;));</span></div> <div><span \
style="color:rgb(204,153,204)">set</span> <span \
style="color:rgb(242,119,122)">resp.http.Location</span> = <span \
style="color:rgb(242,119,122)">resp.reason</span>;</div> <div><span \
style="color:rgb(204,153,204)">set</span> <span \
style="color:rgb(242,119,122)">resp.status</span> = <span \
style="color:rgb(249,145,87)">302</span>;</div> <div><span \
style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">deliver</span>);</div> <div>}</div>
<br>
<div><span style="color:rgb(204,153,204)">return</span> (<span \
style="color:rgb(249,145,87)">deliver</span>);</div> <div>}</div>
</div>
</div>
<div class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto"><br></div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto"><br></div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto">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&#39;t get the \
&quot;Invalidated n objects&quot; message).</div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto"><br></div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto">Not sure where to start debugging…any idea what could cause this?</div> \
<div class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont" \
dir="auto"><br></div> <div \
class="gmail-m_7098675303203673720gmail-m_-1709242024992442460matchFont">—<br> Tim \
Kelty</div> </div>
</div>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" \
target="_blank">varnish-misc@varnish-cache.org</a><br> <a \
href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" \
rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br></blockquote>
 </div>
</blockquote>
</div>
</div>

</blockquote></div>



_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic