vcl_error check backend

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Thu Oct 11 02:12:07 CEST 2012


On Tue, Oct 9, 2012 at 12:08 PM, Daniel Lafraia <lafraia at gmail.com> wrote:
> Is there a way to check which backend was used under vcl_error()?

In my tests, req.backend couldn't be tested on vcl_error (it is null),
so you could set a req.http.header and check it at vcl_error. Like
this:

sub vcl_recv {
  if (req.http.host == "example1.com") {
    set req.backend = be_1;
  } elsif (req.http.host == "example2.com") {
    set req.backend = be_2;
  } else {
    req.backend = be_default;
  }

  set req.http.X-Varnish-Backend = req.backend; # this will convert
the req.backend to string
}

sub vcl_error {
  set obj.http.Content-Type = "text/html; charset=utf-8";
  set obj.http.Retry-After = "5";

  synthetic {"<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>"} + obj.status + " " + obj.response + {"</title>
  </head>
  <body>
    <h1>Error "} + obj.status + " " + obj.response + {"</h1>
    <p>"} + obj.response + {"</p>
    <h3>Guru Meditation:</h3>
    <p>XID: "} + req.xid + {"</p>
    <p>Backend: "} + req.http.X-Varnish-Backend + {"</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>
"};

  return (deliver);
}

-- 
[]'s
Hugo
www.devin.com.br



More information about the varnish-misc mailing list