[Varnish] #777: Documentation on regex with new if parser

Varnish varnish-bugs at varnish-cache.org
Tue Sep 21 15:14:20 CEST 2010


#777: Documentation on regex with new if parser
----------------------+-----------------------------------------------------
 Reporter:  hp197     |       Owner:  kristian
     Type:  defect    |      Status:  new     
 Priority:  lowest    |   Milestone:          
Component:  varnishd  |     Version:  trunk   
 Severity:  minor     |    Keywords:          
----------------------+-----------------------------------------------------

Comment(by hp197):

 {{{
 director loadbalancer round-robin {
         {
                 .backend = {
                         .host = "192.168.x.x";
                         .port = "x";
                         .connect_timeout = 20s;
                         .first_byte_timeout = 50s;
                         .between_bytes_timeout = 20s;
                 }
         }
         {
                 .backend = {
                         .host = "192.168.x.x";
                         .port = "x";
                         .connect_timeout = 20s;
                         .first_byte_timeout = 50s;
                         .between_bytes_timeout = 20s;
                 }
         }
 }

 sub vcl_recv {
         set req.backend = loadbalancer;

         if (req.url ~ "/alive_test.html") {
                 error 200 "1";
         }

         if (req.restarts == 5) {
                 error 418 "I'm a teapot";
         }

         if (req.restarts > 2) {
                 return (pass);
         }

         if (req.request != "GET" && req.request != "HEAD" && req.request
 != "PUT" && req.request != "POST" && req.request != "TRACE" && req.request
 != "OPTIONS" && req.request != "DELETE") {
                 return (pipe);
         }

         remove req.http.Accept-Encoding;
         remove req.http.Accept-Charset;
         remove req.http.Accept-Language;
         remove req.http.Accept;
         remove req.http.Referer;
         remove req.http.Cookie;

         set req.http.host = "xxx.xxx.xxx";

         if ( !req.http.X-Forwarded-For ~
 "^(192\.168\.1\.[0-9]{1,3}|92\.70\.242\.66|94\.210\.246\.167|87\.212\.194\.237)$"
 ) {
                 remove req.http.Cache-Control;
         }

         set req.grace = 2m;
         return (lookup);
 }

 sub vcl_pipe {
         set req.http.connection = "close";
         return (pipe);
 }

 sub vcl_pass {
         return (pass);
 }

 sub vcl_hash {
         hash_data(req.url);
         return (hash);
 }

 sub vcl_hit {
         if (!obj.cacheable) {
                 return (pass);
         }

         if (req.http.Cache-Control ~ "no-cache") {
                 set obj.ttl = 0s;
                 return (restart);
         }

         return (deliver);
 }

 sub vcl_miss {
         if (req.http.Cache-Control ~ "no-cache") {
                 set bereq.http.Cache-Control = "no-cache";
         }

         return (fetch);
 }

 sub vcl_fetch {
         if (beresp.status == 302 || beresp.status == 301 || beresp.status
 == 418) {
                 return (pass);
         }

         remove beresp.http.Set-Cookie;
         remove beresp.http.X-Cache;
         remove beresp.http.Server;
         remove beresp.http.Age;
         set beresp.grace = 2m;

         if (!beresp.cacheable) {
                 return (pass);
         }

         return (deliver);
 }

 sub vcl_deliver {
         remove resp.http.Via;
         remove resp.http.X-Varnish;
         remove resp.http.Set-Cookie;

         if (obj.hits > 0) {
                 set resp.http.X-Cache = "HIT";
         } else {
                 set resp.http.X-Cache = "MISS";
         }
         set resp.http.Server = "us_cache_1";

         return (deliver);
 }

 sub vcl_error {
         if (obj.status == 503 && req.restarts <= 4) {
                 return (restart);
         }

         set obj.http.Content-Type = "text/html; charset=utf-8";

         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>
                 <address>
                         <a href="http://xxx.xxx.xxx">xxx</a>
                 </address>
         </body>
 </html>
 "};

         return (deliver);
 }
 }}}

 Version is trunk revision: 5217

-- 
Ticket URL: <http://www.varnish-cache.org/trac/ticket/777#comment:4>
Varnish <http://varnish-cache.org/>
The Varnish HTTP Accelerator




More information about the varnish-bugs mailing list