<div dir="ltr">Hi,<div><br></div><div>This expectation is wrong:<br> # Here beresp.http.myval (on RHS of assignment expression).<br> # should be the original hdr value stored with the object</div><div><br></div><div>beresp is the new backend response, and VCL doesn't make the old one available.</div><div><br></div><div>There are two ways to deal with this.</div><div><br></div><div>The first one is vmod_stale (<a href="https://docs.varnish-software.com/varnish-cache-plus/vmods/stale/#get-header">https://docs.varnish-software.com/varnish-cache-plus/vmods/stale/#get-header</a>) in Varnish Enterprise that will allow you to get direct access to that header.</div><div><br></div><div>The second one, if you want to stick to open source, uses vcl_hit to stash the old headers in req so that they are available in bereq. That would look something like this (untested code, use with caution):</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">sub vcl_recv {</font></div><div><font face="monospace"> # avoid injections from the clients</font></div><div><font face="monospace"> unset req.http.myval;</font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">sub vcl_hit {</font></div><div><font face="monospace"> # store the header</font></div><div><font face="monospace"> set req.http.myval = obj.http.myval;</font></div><div><font face="monospace">}</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">sub vcl_backend_response {</font></div><div><font face="monospace"> # bereq is basically a req copy, so myval crossed over</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace"> # note that I do that unconditionally here, but you can indeed check bereq.is_bg_fetch</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace"> set beresp.http.myval = bereq.http.myval + " extra string";</font></div><div><font face="monospace">}</font></div></blockquote><div><br></div><div>that should do the trick, however, be careful, the code above will add more text to the header at every background fetch, so you are more than likely to hit the header length limit if you are not careful.</div><div><br></div><div>Does that make sense?</div><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 Wed, Mar 3, 2021 at 8:23 PM Arunabha Saha <<a href="mailto:arunabha.saha@gmail.com">arunabha.saha@gmail.com</a>> 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">Hello,<br>
Something I am trying to do is update an existing value in a<br>
cached object after every background fetch. I can't seem to figure<br>
out how to access the existing object parameters during the background<br>
fetch.<br>
<br>
Example<br>
<br>
vcl_backend_response {<br>
if (!bereq.is_bgfetch) {<br>
set beresp.http.myval = beresp.http.val_from_backend;<br>
} else {<br>
#<br>
#Here beresp.http.myval (on RHS of assignment expression).<br>
# should be the original hdr value stored with the object<br>
but i can't seem to access it this way<br>
# or any other way.<br>
#<br>
set beresp.http.myval = beresp.http.myval +<br>
beresp.http.val_from_backend;<br>
}<br>
}<br>
<br>
-- <br>
regards,<br>
Arun<br>
_______________________________________________<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>