<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap:break-word"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><p class="airmail_on">On 11. September 2017 at 11:44:27, Dridi Boukelmoune (<a href="mailto:dridi@varni.sh">dridi@varni.sh</a>) wrote:</p> <div><blockquote type="cite" class="clean_bq" style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span><div><div></div><div>On Mon, Sep 11, 2017 at 10:52 AM, Eyal Marantenboim<span class="Apple-converted-space"> </span><br><<a href="mailto:eyal.marantenboim@storecast.de">eyal.marantenboim@storecast.de</a>> wrote:<span class="Apple-converted-space"> </span><br>> Hi,<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> We are trying to have varnish respond to all OPTIONS method requests. These<span class="Apple-converted-space"> </span><br>> requests should not go to any backend. They should return the CORS headers<span class="Apple-converted-space"> </span><br>> with an empty body, always (cors headers are added in vcl_deliver).<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> Our problem is that, because of the logic that follows in the config,<span class="Apple-converted-space"> </span><br>> Varnish still ends up picking a backend and adding body, etc.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> I would like to avoid adding everywhere 'if req.method != OPTIONS'..<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> Is there a way in vcl_recv to do something like this:<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> if (req.method ~ "(OPTIONS)"){<span class="Apple-converted-space"> </span><br>> // dont pick backend, finish vcl_recv processing and jump directly to<span class="Apple-converted-space"> </span><br>> vcl_deliver<span class="Apple-converted-space"> </span><br>> }<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> ?<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> Thanks!<span class="Apple-converted-space"> </span><br><br>Hi,<span class="Apple-converted-space"> </span><br><br>You are looking for synthetic responses:<span class="Apple-converted-space"> </span><br><br>sub vcl_recv {<span class="Apple-converted-space"> </span><br>if (req.method == "OPTIONS") {<span class="Apple-converted-space"> </span><br>return (synth(200));<span class="Apple-converted-space"> </span><br>}<span class="Apple-converted-space"> </span><br>}<span class="Apple-converted-space"> </span><br><br>sub vcl_synth {<span class="Apple-converted-space"> </span><br>if (req.method == "OPTIONS") {<span class="Apple-converted-space"> </span><br># set the CORS response headers<span class="Apple-converted-space"> </span><br>return (deliver);<span class="Apple-converted-space"> </span><br>}<span class="Apple-converted-space"> </span><br>}<span class="Apple-converted-space"> </span><br><br>Dridi<span class="Apple-converted-space"> </span></div></div></span></blockquote></div><p><br></p><div id="bloop_customfont" style="margin:0px">Exactly what I was looking for. Thanks!!</div><div><br></div></body></html>