Commit 9d700b96 authored by Łukasz Nowak's avatar Łukasz Nowak Committed by Łukasz Nowak

caddy-frontend: Stabilise slashes (/) during rewrite

/reviewed-on !489
parent 9345c81b
...@@ -58,7 +58,7 @@ md5sum = f20d6c3d2d94fb685f8d26dfca1e822b ...@@ -58,7 +58,7 @@ md5sum = f20d6c3d2d94fb685f8d26dfca1e822b
[template-default-slave-virtualhost] [template-default-slave-virtualhost]
filename = templates/default-virtualhost.conf.in filename = templates/default-virtualhost.conf.in
md5sum = 065bdb954a4c05c538d8264b6ad43fba md5sum = 3b9d7c04206da76edb40740a51e4063c
[template-cached-slave-virtualhost] [template-cached-slave-virtualhost]
filename = templates/cached-virtualhost.conf.in filename = templates/cached-virtualhost.conf.in
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
{%- if slave_parameter.get('custom_domain') not in host_list %} {%- if slave_parameter.get('custom_domain') not in host_list %}
{%- do host_list.append(slave_parameter.get('custom_domain')) %} {%- do host_list.append(slave_parameter.get('custom_domain')) %}
{%- endif %} {%- endif %}
{%- set backend_url = slave_parameter.get('https-url', slave_parameter.get('url', '')) %} {%- set backend_url = slave_parameter.get('https-url', slave_parameter.get('url', '')).rstrip('/') %}
{%- set http_host_list = [] %} {%- set http_host_list = [] %}
{%- set https_host_list = [] %} {%- set https_host_list = [] %}
{%- for host in host_list %} {%- for host in host_list %}
{%- do http_host_list.append('http://%s:%s' % (host, slave_parameter['http_port'] )) %} {%- do http_host_list.append('http://%s:%s' % (host, slave_parameter['http_port'] )) %}
{%- do https_host_list.append('https://%s:%s' % (host, slave_parameter['https_port'] )) %} {%- do https_host_list.append('https://%s:%s' % (host, slave_parameter['https_port'] )) %}
{%- endfor %} {#- for host in host_list #} {%- endfor %} {#- for host in host_list #}
{%- set default_path = slave_parameter.get('default-path', '') | urlencode %} {%- set default_path = slave_parameter.get('default-path', '').strip('/') | urlencode %}
# SSL enabled hosts # SSL enabled hosts
{{ https_host_list|join(', ') }} { {{ https_host_list|join(', ') }} {
...@@ -107,12 +107,12 @@ ...@@ -107,12 +107,12 @@
rewrite { rewrite {
regexp (.*) regexp (.*)
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1} to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '').strip('/') }}%2FVirtualHostRoot/{1}
} }
{%- else %} {%- else %}
rewrite { rewrite {
regexp (.*) regexp (.*)
to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1} to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '').strip('/') }}%2FVirtualHostRoot/{1}
} {# rewrite #} } {# rewrite #}
{%- endif %} {#- if prefer_gzip #} {%- endif %} {#- if prefer_gzip #}
{%- elif slave_type == 'redirect' and backend_url %} {#- if slave_type == 'zope' and backend_url #} {%- elif slave_type == 'redirect' and backend_url %} {#- if slave_type == 'zope' and backend_url #}
...@@ -251,12 +251,12 @@ ...@@ -251,12 +251,12 @@
rewrite { rewrite {
regexp (.*) regexp (.*)
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1} to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '').strip('/') }}%2FVirtualHostRoot/{1}
} }
{%- else %} {%- else %}
rewrite { rewrite {
regexp (.*) regexp (.*)
to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1} to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '').strip('/') }}%2FVirtualHostRoot/{1}
} {# rewrite #} } {# rewrite #}
{% endif %} {#- if prefer_gzip #} {% endif %} {#- if prefer_gzip #}
{%- else %} {#- if https_only #} {%- else %} {#- if https_only #}
......
...@@ -505,10 +505,10 @@ class SlaveHttpFrontendTestCase(HttpFrontendTestCase): ...@@ -505,10 +505,10 @@ class SlaveHttpFrontendTestCase(HttpFrontendTestCase):
certfile=cls.test_server_certificate_file.name, certfile=cls.test_server_certificate_file.name,
server_side=True) server_side=True)
cls.backend_url = 'http://%s:%s' % server.server_address cls.backend_url = 'http://%s:%s/' % server.server_address
cls.server_process = multiprocessing.Process(target=server.serve_forever) cls.server_process = multiprocessing.Process(target=server.serve_forever)
cls.server_process.start() cls.server_process.start()
cls.backend_https_url = 'https://%s:%s' % server_https.server_address cls.backend_https_url = 'https://%s:%s/' % server_https.server_address
cls.server_https_process = multiprocessing.Process( cls.server_https_process = multiprocessing.Process(
target=server_https.serve_forever) target=server_https.serve_forever)
cls.server_https_process.start() cls.server_https_process.start()
...@@ -756,8 +756,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -756,8 +756,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
'url': cls.backend_url, 'url': cls.backend_url,
}, },
'url_https-url': { 'url_https-url': {
'url': cls.backend_url + '/http', 'url': cls.backend_url + 'http',
'https-url': cls.backend_url + '/https', 'https-url': cls.backend_url + 'https',
}, },
'server-alias': { 'server-alias': {
'url': cls.backend_url, 'url': cls.backend_url,
...@@ -870,12 +870,12 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -870,12 +870,12 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
'type-zope-path': { 'type-zope-path': {
'url': cls.backend_url, 'url': cls.backend_url,
'type': 'zope', 'type': 'zope',
'path': 'path', 'path': '///path/to/some/resource///',
}, },
'type-zope-default-path': { 'type-zope-default-path': {
'url': cls.backend_url, 'url': cls.backend_url,
'type': 'zope', 'type': 'zope',
'default-path': 'default-path', 'default-path': '///default-path/to/some/resource///',
}, },
'type-notebook': { 'type-notebook': {
'url': cls.backend_url, 'url': cls.backend_url,
...@@ -1264,8 +1264,10 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1264,8 +1264,10 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
self.assertEqualResultJson( self.assertEqualResultJson(
result, result,
'Path', 'Path',
'/VirtualHostBase/https//' '/VirtualHostBase/'
'typezopepath.example.com:443/path/VirtualHostRoot/test-path/deeper' 'https//typezopepath.example.com:443/path/to/some/resource'
'/VirtualHostRoot/'
'test-path/deeper'
) )
def test_type_zope_default_path(self): def test_type_zope_default_path(self):
...@@ -1296,7 +1298,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1296,7 +1298,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
self.assertEqual( self.assertEqual(
'https://typezopedefaultpath.example.com:%s/default-path' % ( 'https://typezopedefaultpath.example.com:%s/'
'default-path/to/some/resource' % (
HTTPS_PORT,), HTTPS_PORT,),
result.headers['Location'] result.headers['Location']
) )
...@@ -1952,7 +1955,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1952,7 +1955,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
self.assertEqual( self.assertEqual(
'%s/test-path/deeper' % (self.backend_url,), '%stest-path/deeper' % (self.backend_url,),
result.headers['Location'] result.headers['Location']
) )
......
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