Add support for doing ESI on pages in Varnish
authorMagnus Hagander <magnus@hagander.net>
Fri, 29 Jun 2018 15:59:04 +0000 (17:59 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 29 Jun 2018 16:03:25 +0000 (18:03 +0200)
pgweb/settings.py
pgweb/util/contexts.py
pgweb/util/middleware.py
templates/base/esi.html [new file with mode: 0644]

index 33d07e86544c80d982a25888a2adc7bc938c42e0..11789ecc8208d25b0728b72e28aefd52bfa4f8d9 100644 (file)
@@ -154,6 +154,7 @@ FRONTEND_SERVERS=()                                    # A tuple containing the
 FTP_MASTERS=()                                                                            # A tuple containing the *IP addresses* of all machines
                                                        # trusted to upload ftp structure data
 VARNISH_PURGERS=()                                     # Extra servers that can do varnish purges through our queue
+DO_ESI=False                                           # Generate ESI tags
 ARCHIVES_SEARCH_SERVER="archives.postgresql.org"       # Where to post REST request for archives search
 ARCHIVES_SEARCH_PLAINTEXT=False                        # Contact ARCHIVES_SEARCH_SERVER with http instead of https
 FRONTEND_SMTP_RELAY="magus.postgresql.org"             # Where to relay user generated email
index 2883ea3be9e17f734265b6e7263ae954c8bc3b35..b19550715ca974083cb97d769cc0a76a6edaafb5 100644 (file)
@@ -121,9 +121,11 @@ def PGWebContextProcessor(request):
        if request.is_secure():
                return {
                        'link_root': settings.SITE_ROOT,
+                       'do_esi': settings.DO_ESI,
                        'gitrev': gitrev,
                }
        else:
                return {
                        'gitrev': gitrev,
+                       'do_esi': settings.DO_ESI,
                }
index 28d4416ebd57eb7caf4b108883eb005fe224c0b8..d8d46811e57d07a67d9ab1d24690cefc101c3ada 100644 (file)
@@ -26,5 +26,10 @@ class PgMiddleware(object):
                initialize_template_collection()
 
        def process_response(self, request, response):
-               response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t).hexdigest()) for t in get_all_templates()])
+               tlist = get_all_templates()
+               if 'base/esi.html' in tlist:
+                       response['x-do-esi'] = "1"
+                       tlist.remove('base/esi.html')
+               if tlist:
+                       response['xkey'] = ' '.join(["pgwt_{0}".format(hashlib.md5(t).hexdigest()) for t in tlist])
                return response
diff --git a/templates/base/esi.html b/templates/base/esi.html
new file mode 100644 (file)
index 0000000..1f04970
--- /dev/null
@@ -0,0 +1,3 @@
+{%if do_esi %}<esi:include src="{{includepage}}/xx"/>{%else%}
+{%include "pages"|add:includepage|add:".html"%}
+{%endif%}