Why use status code 750 for redirects?

Bjørn Ruberg bjorn at ruberg.no
Fri Dec 21 23:15:57 CET 2012


On 12/21/2012 10:48 PM, James Pearson wrote:
> In the Varnish book (and every site reposting the same example), we are shown
> how to make a redirect in VCL by using 'error 750'.[1]  This seems more
> roundabout than necessary - why not just use 'error 302'?  It'll end up being
> the same to the users, but is more clear in its intention.
>
> The only reason I can think of for not doing that is if you have any cases
> where you want to display an error page with a 302 status code, but *not*
> redirect.  But why would you want to do that?
>
> [1]: https://www.varnish-software.com/static/book/VCL_functions.html#example-redirecting-users-with-vcl-error
>

As you can see from the example you're referring to, the error 750 
defined in vcl_recv is later handled in vcl_error and "translated" to a 301.

Inside the VCL, it's often useful to define internal error codes that 
may be referred to several times, and then they are picked up in 
vcl_error where the error code is translated into something that the end 
user (or rather the browser) understands. Error codes used for internal 
handling within the VCL should not be within the numerical range where 
you'd find normal error codes.

Let's say you have a lot of situations in your VCL where you need to 
redirect to a login URL - then it's easy and efficient to define that 
redirect *once*, label it e.g. error 751, and then return "error 751;" 
where applicable in the VCL.

Of course, if you don't want or need any special handling of errors, 
you're at liberty to return a regular error code whenever you want to.

-- 
Bjørn




More information about the varnish-misc mailing list