Checking if a host header value is true

Michael Alger varnish at mm.quex.org
Wed Aug 3 07:11:37 CEST 2011


On Wed, Aug 03, 2011 at 12:26:27AM -0400, Kevin wrote:
> 
> Forgive my question but I am curious how it is possible to check if a
> host header value is true in varnish. For instance :
> 
> If (host header X-value-whatever == "true" ){
> 
> return(pipe);
> 
> }
> 
> Can someone clarify how this would be done?

Your wording is a little unclear, since the Host header is a specific
header, and you're saying "_a_ host header". So, what I think you mean
is a request header, as that's where you typically see the Host: header.

In vcl_fetch, you can access request header fields via the req object:

  if (req.http.x-value-whatever == "true")

The x-value-whatever is _not_ case-sensitive, so

  if (req.http.X-Value-Whatever == "true")

will work exactly the same as the previous example.

If you actually want to inspect the host header in particular, it's

  if (req.http.Host == "some.host")

If you want to know whether or not a particular header is present in a
request, you can use:

  if (req.http.X-Value-Whatever)

which will evaluate as true if that header was supplied with the
request, or

  if (! req.http.X-Value-Whatever)

which will evaluate as true if that header was _not_ supplied.




More information about the varnish-misc mailing list