Mailing List Archive

Is there a way to force exit vcl_recv?
Hi,

We are trying to have varnish respond to all OPTIONS method requests. These
requests should not go to any backend. They should return the CORS headers
with an empty body, always (cors headers are added in vcl_deliver).

Our problem is that, because of the logic that follows in the config,
Varnish still ends up picking a backend and adding body, etc.

I would like to avoid adding everywhere 'if req.method != OPTIONS'..

Is there a way in vcl_recv to do something like this:

if (req.method ~ "(OPTIONS)"){
// dont pick backend, finish vcl_recv processing and jump directly to
vcl_deliver
}

?

Thanks!
Re: Is there a way to force exit vcl_recv? [ In reply to ]
On Mon, Sep 11, 2017 at 10:52 AM, Eyal Marantenboim
<eyal.marantenboim@storecast.de> wrote:
> Hi,
>
> We are trying to have varnish respond to all OPTIONS method requests. These
> requests should not go to any backend. They should return the CORS headers
> with an empty body, always (cors headers are added in vcl_deliver).
>
> Our problem is that, because of the logic that follows in the config,
> Varnish still ends up picking a backend and adding body, etc.
>
> I would like to avoid adding everywhere 'if req.method != OPTIONS'..
>
> Is there a way in vcl_recv to do something like this:
>
> if (req.method ~ "(OPTIONS)"){
> // dont pick backend, finish vcl_recv processing and jump directly to
> vcl_deliver
> }
>
> ?
>
> Thanks!

Hi,

You are looking for synthetic responses:

sub vcl_recv {
if (req.method == "OPTIONS") {
return (synth(200));
}
}

sub vcl_synth {
if (req.method == "OPTIONS") {
# set the CORS response headers
return (deliver);
}
}

Dridi
_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Is there a way to force exit vcl_recv? [ In reply to ]
On 11. September 2017 at 11:44:27, Dridi Boukelmoune (dridi@varni.sh) wrote:

On Mon, Sep 11, 2017 at 10:52 AM, Eyal Marantenboim
<eyal.marantenboim@storecast.de> wrote:
> Hi,
>
> We are trying to have varnish respond to all OPTIONS method requests.
These
> requests should not go to any backend. They should return the CORS headers

> with an empty body, always (cors headers are added in vcl_deliver).
>
> Our problem is that, because of the logic that follows in the config,
> Varnish still ends up picking a backend and adding body, etc.
>
> I would like to avoid adding everywhere 'if req.method != OPTIONS'..
>
> Is there a way in vcl_recv to do something like this:
>
> if (req.method ~ "(OPTIONS)"){
> // dont pick backend, finish vcl_recv processing and jump directly to
> vcl_deliver
> }
>
> ?
>
> Thanks!

Hi,

You are looking for synthetic responses:

sub vcl_recv {
if (req.method == "OPTIONS") {
return (synth(200));
}
}

sub vcl_synth {
if (req.method == "OPTIONS") {
# set the CORS response headers
return (deliver);
}
}

Dridi


Exactly what I was looking for. Thanks!!