<div dir="ltr">Hi,<div><br></div><div>There are a few things to do here:</div><div>- make sure that if req.method == "POST", you return(hash) from vcl_recv (otherwise, the builtin.vcl (<a href="https://github.com/varnish/Varnish-Cache/blob/4.1/bin/varnishd/builtin.vcl#L63">https://github.com/varnish/Varnish-Cache/blob/4.1/bin/varnishd/builtin.vcl#L63</a>) will pass)</div><div>- but before that, add 'set req.http.x-method = req.method' at the top of vcl_recv, and 'if (bereq.http.x-method == "POST") {set bereq.method = "POST"; }' at the top of vcl_backend_fetch, because for cacheable request, varnish will want to set the method to "GET", so we need to reset it back</div><div><br></div><div>On top of that:</div><div>- you can use req.hash_always_miss (man vcl) to push new content (and avoid just getting the cached response)</div><div>- make sure you only cache when the response is OK, otherwise a wrong POST request will mask the previous valid ones</div><div>- if you are acting upon the URL of the resource itself, I'd say it should be a PUT/PATCH, rather than a POST, but that's just pedantry at this point</div><div>- realize that the content cached is the response returned by the backend, not the body of the request itself. They may be the same, but maybe not (there are ways to do it though)</div><div><br></div><div>Hope that helps</div><div>-- </div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Guillaume Quintard<br></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 11, 2019 at 10:42 PM Yuan Zafir <<a href="mailto:eyz12315@live.cn">eyz12315@live.cn</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">
<div>
<div><span></span>Hi,<span style="color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;line-height:inherit;background-color:transparent">I am trying to configure varnish as a simple
cache service, which means the content posted by clients could be cached as an object. The content chould be returned in responses for the coming GET requests(with same url...). I am not sure wether this can be realized by VCL configuration.</span></div>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-ligatures:normal;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">
Any recommendation for this situation? Thanks for any help!</p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-variant-ligatures:normal;font-stretch:inherit;line-height:inherit;font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:15px;vertical-align:baseline;box-sizing:inherit;clear:both;color:rgb(36,39,41)">
I was noticed vmod-bodyaccess can cache req.body and then it could be used in bereq(<a href="https://info.varnish-software.com/blog/caching-post-requests-with-varnish" rel="nofollow noreferrer" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit;color:rgb(0,89,153)" target="_blank">https://info.varnish-software.com/blog/caching-post-requests-with-varnish</a>),
but I do not know how to put it into responses for clients.</p>
<div><br>
</div>
<div>thanks!</div>
<div>Zafir</div>
<hr style="width:210px;height:1px" color="#b5c4df" size="1" align="left">
<div><span>
<div style="margin:10px;font-family:verdana;font-size:10pt">
<div><a href="mailto:eyz12315@live.cn" target="_blank">eyz12315@live.cn</a></div>
</div>
</span></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>