VCL 4 resp.reason, vcl_synth and redirection

Kervin L. Pierre kervin at adevsoft.com
Mon Aug 3 20:05:56 CEST 2015


One common practice with VCL 3 was to use vcl_error() for redirect, and
with the reason carrying the location.

This was useful since the location may vary and was generated in
vcl_recv().  Hence there needed a way for the generated HTTP Location
header to be sent to vcl_error.

With VCL 4, this can still be done with resp.reason *but* only if the
resp.reason is used *before* resp.status is set.  This is because
setting resp.status seems to reset resp.reason

Hence the following works ( if I've previously set resp.reason to the
location in vcl_recv )...

sub vcl_synth {
    if (resp.status == 750) {
        set resp.http.Location = resp.reason;
        set resp.status = 301;
        return(deliver);
    }
}

But the following does NOT work...

sub vcl_synth {
    if (resp.status == 750) {
        set resp.status = 301; // Resets reason
        set resp.http.Location = resp.reason;
        return(deliver);
    }
}

Is there a "better" or "clearer" way to pass a location to vcl_synth?

Best regards,
Kervin



More information about the varnish-misc mailing list