title: Varnish variables and DRY code
body: <p>As a python engineer one learns to write DRY style code; not because it's a buzzword, but it makes your code cleaner looking and readable to others.  </p>
  
  <p>Anyone who's endured reading a former colleague's code can understand that well.</p>
  
  <p>With varnish, there's not variable assignment so how can one even attempt to write DRY style rules?</p>
  
  <p>Consider the following: </p>
  
  <p>I have a cluster of backend instances running apache with over ten <code>vhosts</code>.  There's a front end instance that needs to re-write based on the <code>vhost</code>.</p>
  
  <p>I'm stuck with this:</p>
  
  <pre><code>if ( req.url ~ "^/amp/" ) {
      # vhost's AMP code == xyz
      if (req.http.host = "host1.com") {
         set req.url = regsub(req.url, "/amp/",  "/nps/$host1-brand-code/");
      }
       if (req.http.host = "host2.com") {
         set req.url = regsub(req.url, "/amp/",  "/nps/$host2-brand-code/");
      }
      ...
  }
  </code></pre>
  
  <p>What's upsetting here is the repeat of <code>regsub</code> </p>
  
  <pre><code>"/nps/$host1-brand-code/"
  </code></pre>
  
  <p>What if the publishers decide to change that next month to <code>/new-nps-url/$host1-brand-code</code>.  I will be forced to update many if statements for just one cluster, and we have many clusters!</p>