From: Magnus Hagander Date: Fri, 29 Jun 2018 15:59:04 +0000 (+0200) Subject: Add support for doing ESI on pages in Varnish X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=747cc8f06a73d15330b860c105bf595754606635;p=pgweb.git Add support for doing ESI on pages in Varnish --- diff --git a/pgweb/settings.py b/pgweb/settings.py index 33d07e86..11789ecc 100644 --- a/pgweb/settings.py +++ b/pgweb/settings.py @@ -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 diff --git a/pgweb/util/contexts.py b/pgweb/util/contexts.py index 2883ea3b..b1955071 100644 --- a/pgweb/util/contexts.py +++ b/pgweb/util/contexts.py @@ -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, } diff --git a/pgweb/util/middleware.py b/pgweb/util/middleware.py index 28d4416e..d8d46811 100644 --- a/pgweb/util/middleware.py +++ b/pgweb/util/middleware.py @@ -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 index 00000000..1f049704 --- /dev/null +++ b/templates/base/esi.html @@ -0,0 +1,3 @@ +{%if do_esi %}{%else%} +{%include "pages"|add:includepage|add:".html"%} +{%endif%}