<commit_before><% @node[:varnish][:app_proxy_host].each_with_index do |host, i| %>
  backend app_server_<%= i+1 %> {
    .host = "<%= host %>";
    .port = "<%= @node[:varnish][:app_proxy_port] %>";
    .probe = {
               .url = "<%= @node[:varnish][:app_proxy_host_probe_url] %>";
               .interval = 5s;
               .timeout = 1 s;
               .window = 5;
               .threshold = 3;
    }
  }
<% end %>


backend static_server {
  .host = "<%= @node[:varnish][:static_proxy_host] %>";
  .port = "<%= @node[:varnish][:static_proxy_port] %>";
}

director app_director round-robin {
  <% @node[:varnish][:app_proxy_host].each_with_index do |host, i| %>
    { .backend = app_server_<%= i+1 %>; }
  <% end %>
}

sub vcl_recv {
    # Reject Non-RFC2616 or CONNECT or TRACE requests.
    if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
        return (pipe);
    }
    
    # Compression handled upstream; only want one in the cache
    if (req.http.Accept-Encoding) {
        remove req.http.Accept-Encoding;
    }
  
    # serve slightly stale content while a fresh version is fetched
    # better user experience and no thread pile up on the app servers
    set req.grace = 24h;
  
    # set the backend server based on request (if multi-server stack)
  <% if @node[:chef][:roles].include?('staging') %>
    set req.backend = app_server_1;
  <% elsif @node[:chef][:roles].include?('proxy') %>
    if (req.url ~ "^(/images|/javascripts|/flash|/stylesheets|/sitemap|/articles/html|/articles/xml|/regulations/html)") {
      set req.backend = static_server;
      return (lookup);
    } else {
      set req.backend = app_director;
    }
  <% end %>
    
  
    # NOT NEEDED WHEN USING A PROXY SERVER IN FRONT LIKE NGINX
    # Add a unique header containing the client address
    # remove req.http.X-Forwarded-For;
    # set    req.http.X-Forwarded-For = client.ip;
    
    # Pass POSTs etc directly on to the backend
    if (req.request != "GET" && req.request != "HEAD") {
        return (pass);
    }
    
    # Pass admin requests directly on to the backend
    if (req.url ~ "^/admin/") {
        return (pass);
    }

    # Remove cookies for anything that doesn't match the following
    if (req.url !~ "^(/login|/logout|/admin)") {
      unset req.http.cookie;
    }

    # Prevent duplication of caches
    set req.http.host = "<%= @node[:varnish][:proxy_host_name] %>";
    
    # Check to see if cached
    return (lookup);
}

sub vcl_fetch {<commit_msg>Set cache request host to use www since we rewrite all urls to www per most gov sites<commit_after><% @node[:varnish][:app_proxy_host].each_with_index do |host, i| %>
backend app_server_<%= i+1 %> {
  .host = "<%= host %>";
  .port = "<%= @node[:varnish][:app_proxy_port] %>";
  .probe = {
             .url = "<%= @node[:varnish][:app_proxy_host_probe_url] %>";
             .interval = 5s;
             .timeout = 1 s;
             .window = 5;
             .threshold = 3;
  }
}
<% end %>

<% if @node[:chef][:roles].include?('proxy') %>
backend static_server {
  .host = "<%= @node[:varnish][:static_proxy_host] %>";
  .port = "<%= @node[:varnish][:static_proxy_port] %>";
}

director app_director round-robin {
  <% @node[:varnish][:app_proxy_host].each_with_index do |host, i| %>
    { .backend = app_server_<%= i+1 %>; }
  <% end %>
}
<% end %>

sub vcl_recv {
    # Reject Non-RFC2616 or CONNECT or TRACE requests.
    if (req.request != "GET" &&
      req.request != "HEAD" &&
      req.request != "PUT" &&
      req.request != "POST" &&
      req.request != "OPTIONS" &&
      req.request != "DELETE") {
        return (pipe);
    }
    
    # Compression handled upstream; only want one in the cache
    if (req.http.Accept-Encoding) {
        remove req.http.Accept-Encoding;
    }
  
    # serve slightly stale content while a fresh version is fetched
    # better user experience and no thread pile up on the app servers
    set req.grace = 24h;
  
    # set the backend server based on request (if multi-server stack)
  <% if @node[:chef][:roles].include?('staging') %>
    set req.backend = app_server_1;
  <% elsif @node[:chef][:roles].include?('proxy') %>
    if (req.url ~ "^(/images|/javascripts|/flash|/stylesheets|/sitemap|/articles/html|/articles/xml|/regulations/html)") {
      set req.backend = static_server;
      return (lookup);
    } else {
      set req.backend = app_director;
    }
  <% end %>
    
  
    # NOT NEEDED WHEN USING A PROXY SERVER IN FRONT LIKE NGINX
    # Add a unique header containing the client address
    # remove req.http.X-Forwarded-For;
    # set    req.http.X-Forwarded-For = client.ip;
    
    # Pass POSTs etc directly on to the backend
    if (req.request != "GET" && req.request != "HEAD") {
        return (pass);
    }
    
    # Pass admin requests directly on to the backend
    if (req.url ~ "^/admin/") {
        return (pass);
    }

    # Remove cookies for anything that doesn't match the following
    if (req.url !~ "^(/login|/logout|/admin)") {
      unset req.http.cookie;
    }

    # Prevent duplication of caches
    set req.http.host = "www.<%= @node[:varnish][:proxy_host_name] %>";
    
    # Check to see if cached
    return (lookup);
}

sub vcl_fetch {
{'fraction_non_alphanumeric': 0.15737460376654858, 'fraction_numerical': 0.004848032817452918, 'mean_word_length': 2.552317880794702, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '357384', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1794, 'n_words': 453}