Commit 1de9f5d1 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

caddy-frontend: Implement prefer-gzip-encoding-to-backend

Desipte of original analysis the middleware plugin is not needed, as Caddy's
http.rewrite + http.proxy is powerful enough to set headers depending on the
header regular expression.
parent 17679616
...@@ -6,9 +6,6 @@ Generally things to be done with ``caddy-frontend``: ...@@ -6,9 +6,6 @@ Generally things to be done with ``caddy-frontend``:
* **Jérome Perrin**: *For event source, if I understand https://github.com/mholt/caddy/issues/1355 correctly, we could use caddy as a proxy in front of nginx-push-stream . If we have a "central shared" caddy instance, can it handle keeping connections opens for many clients ?* * **Jérome Perrin**: *For event source, if I understand https://github.com/mholt/caddy/issues/1355 correctly, we could use caddy as a proxy in front of nginx-push-stream . If we have a "central shared" caddy instance, can it handle keeping connections opens for many clients ?*
* ``ssl_ca_crt`` * ``ssl_ca_crt``
* ``prefer-gzip-encoding-to-backend`` (requires writing middleware plugin for Caddy)::
RequestHeader edit Accept-Encoding "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" "gzip"
* ``disabled-cookie-list`` (requires writing middleware plugin for Caddy):: * ``disabled-cookie-list`` (requires writing middleware plugin for Caddy)::
RequestHeader edit Cookie "(^%(disabled_cookie)s=[^;]*; |; %(disabled_cookie)s=[^;]*|^%(disabled_cookie)s=[^;]*$)" ""' % dict(disabled_cookie=disabled_cookie) }} RequestHeader edit Cookie "(^%(disabled_cookie)s=[^;]*; |; %(disabled_cookie)s=[^;]*|^%(disabled_cookie)s=[^;]*$)" ""' % dict(disabled_cookie=disabled_cookie) }}
......
...@@ -50,7 +50,7 @@ md5sum = f20d6c3d2d94fb685f8d26dfca1e822b ...@@ -50,7 +50,7 @@ md5sum = f20d6c3d2d94fb685f8d26dfca1e822b
[template-default-slave-virtualhost] [template-default-slave-virtualhost]
filename = templates/default-virtualhost.conf.in filename = templates/default-virtualhost.conf.in
md5sum = aca244bf8792793800895bf2e5310787 md5sum = 6da56d875f5cf396f8fd0685cf1a9a7a
[template-cached-slave-virtualhost] [template-cached-slave-virtualhost]
filename = templates/cached-virtualhost.conf.in filename = templates/cached-virtualhost.conf.in
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
{%- set disable_no_cache_header = ('' ~ slave_parameter.get('disable-no-cache-request', '')).lower() in TRUE_VALUES %} {%- set disable_no_cache_header = ('' ~ slave_parameter.get('disable-no-cache-request', '')).lower() in TRUE_VALUES %}
{%- set disable_via_header = ('' ~ slave_parameter.get('disable-via-header', '')).lower() in TRUE_VALUES %} {%- set disable_via_header = ('' ~ slave_parameter.get('disable-via-header', '')).lower() in TRUE_VALUES %}
{%- set prefer_gzip = ('' ~ slave_parameter.get('prefer-gzip-encoding-to-backend', '')).lower() in TRUE_VALUES %} {%- set prefer_gzip = ('' ~ slave_parameter.get('prefer-gzip-encoding-to-backend', '')).lower() in TRUE_VALUES %}
{%- set proxy_append_list = [('', 'Default proxy configuration')] %}
{%- if prefer_gzip %}
{%- do proxy_append_list.append(('prefer-gzip', 'Proxy which always overrides Accept-Encoding to gzip if such is found')) %}
{%- endif %} {#- if prefer_gzip #}
{%- set server_alias_list = slave_parameter.get('server-alias', '').split() %} {%- set server_alias_list = slave_parameter.get('server-alias', '').split() %}
{%- set enable_h2 = ('' ~ slave_parameter.get('enable-http2', slave_parameter['enable_http2_by_default'])).lower() in TRUE_VALUES %} {%- set enable_h2 = ('' ~ slave_parameter.get('enable-http2', slave_parameter['enable_http2_by_default'])).lower() in TRUE_VALUES %}
{%- set ssl_proxy_verify = ('' ~ slave_parameter.get('ssl-proxy-verify', '')).lower() in TRUE_VALUES %} {%- set ssl_proxy_verify = ('' ~ slave_parameter.get('ssl-proxy-verify', '')).lower() in TRUE_VALUES %}
...@@ -45,11 +49,21 @@ ...@@ -45,11 +49,21 @@
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #} {%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
{%- if prefer_gzip %} {%- if prefer_gzip %}
rewrite {
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip{uri}
}
{%- endif %} {#- if prefer_gzip #} {%- endif %} {#- if prefer_gzip #}
{%- if slave_type == 'zope' and backend_url %} {%- if slave_type == 'zope' and backend_url %}
# Zope configuration # Zope configuration
proxy / {{ backend_url }} { {%- for (proxy_name, proxy_comment) in proxy_append_list %}
# {{ proxy_comment }}
proxy /{{ proxy_name }} {{ backend_url }} {
{%- if proxy_name == 'prefer-gzip' %}
without /prefer-gzip
header_upstream Accept-Encoding gzip
{%- endif %} {#- if proxy_name == 'prefer-gzip' #}
# As backend is trusting REMOTE_USER header unset it always # As backend is trusting REMOTE_USER header unset it always
header_upstream -REMOTE_USER header_upstream -REMOTE_USER
...@@ -70,6 +84,7 @@ ...@@ -70,6 +84,7 @@
insecure_skip_verify insecure_skip_verify
{%- endif %} {#- if ssl_proxy_verify #} {%- endif %} {#- if ssl_proxy_verify #}
} {# proxy #} } {# proxy #}
{%- endfor %} {#- for (proxy_name, proxy_comment) in proxy_append_list #}
{%- if 'default-path' in slave_parameter %} {%- if 'default-path' in slave_parameter %}
redir 301 { redir 301 {
if {path} is / if {path} is /
...@@ -95,7 +110,13 @@ ...@@ -95,7 +110,13 @@
{%- endif %} {#- if 'default-path' in slave_parameter #} {%- endif %} {#- if 'default-path' in slave_parameter #}
{%- if backend_url %} {%- if backend_url %}
proxy / {{ backend_url }} { {%- for (proxy_name, proxy_comment) in proxy_append_list %}
# {{ proxy_comment }}
proxy /{{ proxy_name }} {{ backend_url }} {
{%- if proxy_name == 'prefer-gzip' %}
without /prefer-gzip
header_upstream Accept-Encoding gzip
{%- endif %} {#- if proxy_name == 'prefer-gzip' #}
# As backend is trusting REMOTE_USER header unset it always # As backend is trusting REMOTE_USER header unset it always
header_upstream -REMOTE_USER header_upstream -REMOTE_USER
...@@ -116,6 +137,7 @@ ...@@ -116,6 +137,7 @@
insecure_skip_verify insecure_skip_verify
{%- endif %} {#- if ssl_proxy_verify #} {%- endif %} {#- if ssl_proxy_verify #}
} {# proxy #} } {# proxy #}
{%- endfor %} {#- for (proxy_name, proxy_comment) in proxy_append_list #}
{%- endif %} {#- if backend_url #} {%- endif %} {#- if backend_url #}
{%- endif %} {#- if slave_type == 'zope' and backend_url #} {%- endif %} {#- if slave_type == 'zope' and backend_url #}
} {# https_host_list|join(', ') #} } {# https_host_list|join(', ') #}
...@@ -136,6 +158,10 @@ ...@@ -136,6 +158,10 @@
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #} {%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
{%- if prefer_gzip %} {%- if prefer_gzip %}
rewrite {
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip{uri}
}
{%- endif %} {#- if prefer_gzip #} {%- endif %} {#- if prefer_gzip #}
{%- if https_only %} {%- if https_only %}
...@@ -148,7 +174,13 @@ ...@@ -148,7 +174,13 @@
} {# redir #} } {# redir #}
{%- elif slave_type == 'zope' and backend_url %} {#- if https_only #} {%- elif slave_type == 'zope' and backend_url %} {#- if https_only #}
# Zope configuration # Zope configuration
proxy / {{ backend_url }} { {%- for (proxy_name, proxy_comment) in proxy_append_list %}
# {{ proxy_comment }}
proxy /{{ proxy_name }} {{ backend_url }} {
{%- if proxy_name == 'prefer-gzip' %}
without /prefer-gzip
header_upstream Accept-Encoding gzip
{%- endif %} {#- if proxy_name == 'prefer-gzip' #}
# As backend is trusting REMOTE_USER header unset it always # As backend is trusting REMOTE_USER header unset it always
header_upstream -REMOTE_USER header_upstream -REMOTE_USER
...@@ -169,6 +201,7 @@ ...@@ -169,6 +201,7 @@
insecure_skip_verify insecure_skip_verify
{%- endif %} {#- if ssl_proxy_verify #} {%- endif %} {#- if ssl_proxy_verify #}
} {# proxy #} } {# proxy #}
{%- endfor %} {#- for (proxy_name, proxy_comment) in proxy_append_list #}
{%- if 'default-path' in slave_parameter %} {%- if 'default-path' in slave_parameter %}
redir 301 { redir 301 {
if {path} is / if {path} is /
...@@ -188,7 +221,13 @@ ...@@ -188,7 +221,13 @@
} {# redir #} } {# redir #}
{%- endif %} {#- if 'default-path' in slave_parameter #} {%- endif %} {#- if 'default-path' in slave_parameter #}
{%- if slave_parameter.get('url', '') %} {%- if slave_parameter.get('url', '') %}
proxy / {{ slave_parameter.get('url', '') }} { {%- for (proxy_name, proxy_comment) in proxy_append_list %}
# {{ proxy_comment }}
proxy /{{ proxy_name }} {{ slave_parameter.get('url', '') }} {
{%- if proxy_name == 'prefer-gzip' %}
without /prefer-gzip
header_upstream Accept-Encoding gzip
{%- endif %} {#- if proxy_name == 'prefer-gzip' #}
# As backend is trusting REMOTE_USER header unset it always # As backend is trusting REMOTE_USER header unset it always
header_upstream -REMOTE_USER header_upstream -REMOTE_USER
...@@ -209,6 +248,7 @@ ...@@ -209,6 +248,7 @@
insecure_skip_verify insecure_skip_verify
{%- endif %} {#- if ssl_proxy_verify #} {%- endif %} {#- if ssl_proxy_verify #}
} {# proxy #} } {# proxy #}
{%- endfor %} {#- for (proxy_name, proxy_comment) in proxy_append_list #}
{%- endif %} {#- if slave_parameter.get('url', '') #} {%- endif %} {#- if slave_parameter.get('url', '') #}
{%- endif %} {#- if https_only #} {%- endif %} {#- if https_only #}
} {# http_host_list|join(', ') #} } {# http_host_list|join(', ') #}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment