From a3b3d6a85bba24139e5ea116f7e7368b9a25e7ce Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Tue, 23 Jul 2019 17:39:04 +0200
Subject: [PATCH] ansible-inventories/arocom#2812 Allow to avoid Varnish on a
 per-request-basis by using a special request header

---
 templates/haproxy_cfg.jinja2 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/templates/haproxy_cfg.jinja2 b/templates/haproxy_cfg.jinja2
index fa327e4..7544eee 100644
--- a/templates/haproxy_cfg.jinja2
+++ b/templates/haproxy_cfg.jinja2
@@ -162,6 +162,7 @@ frontend http_in
 {% endif %}
   acl domain_uses_bigpipe hdr(host) -i -n -f /etc/haproxy/use_bigpipe.list
 {% if varnish_host|default(false) %}
+  acl request_ignores_varnish hdr(x-varnish-ignore) -m found
   acl is_purge method PURGE
   use_backend backend_varnish if is_purge
   acl is_ban method BAN
@@ -173,8 +174,8 @@ frontend http_in
   acl domain_ignores_varnish hdr(host) -i -n -f /etc/haproxy/ignore_varnish.list
   acl static_content path_end .jpg .jpeg .gif .png .ico .swf .css .js .htm .html .ttf .woff .woff2 .svg .eot
   acl static_content_private path_beg /system/
-  use_backend backend_varnish_bigpipe if static_content !static_content_private domain_uses_bigpipe !domain_ignores_varnish
-  use_backend backend_varnish if static_content !static_content_private !domain_ignores_varnish
+  use_backend backend_varnish_bigpipe if static_content !static_content_private domain_uses_bigpipe !domain_ignores_varnish !request_ignores_varnish
+  use_backend backend_varnish if static_content !static_content_private !domain_ignores_varnish !request_ignores_varnish
 {% endif %}
 {% if 'webserver' in groups %}
 {% for host in groups['webserver']|sort %}
@@ -307,11 +308,12 @@ frontend https_in_{{ cert.ip }}
 {% endif %}
   acl domain_uses_bigpipe hdr(host) -i -n -f /etc/haproxy/use_bigpipe.list
 {% if varnish_host|default(false) %}
+  acl request_ignores_varnish hdr(x-varnish-ignore) -m found
   acl domain_ignores_varnish hdr(host) -i -n -f /etc/haproxy/ignore_varnish.list
   acl static_content path_end .jpg .jpeg .gif .png .ico .swf .css .js .htm .html .ttf .woff .woff2 .svg .eot
   acl static_content_private path_beg /system/
-  use_backend backend_varnish_bigpipe if static_content !static_content_private domain_uses_bigpipe !domain_ignores_varnish
-  use_backend backend_varnish if static_content !static_content_private !domain_ignores_varnish
+  use_backend backend_varnish_bigpipe if static_content !static_content_private domain_uses_bigpipe !domain_ignores_varnish !request_ignores_varnish
+  use_backend backend_varnish if static_content !static_content_private !domain_ignores_varnish !request_ignores_varnish
 {% endif %}
 {% if 'webserver' in groups %}
 {% for host in groups['webserver']|sort %}
-- 
GitLab