Commit c02f19d5 authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Do path normalization

By using simple rewrite with full regexp the Caddy's rewrite system will do
path normalization, which is required in many cases.
parent 346760af
...@@ -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 = f0ba7b878f374b05265fadea469c73ca md5sum = a7aff60871c66846a623bcecca1851c4
[template-cached-slave-virtualhost] [template-cached-slave-virtualhost]
filename = templates/cached-virtualhost.conf.in filename = templates/cached-virtualhost.conf.in
......
...@@ -42,12 +42,17 @@ ...@@ -42,12 +42,17 @@
log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}" log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}"
errors {{ slave_parameter.get('error_log') }} errors {{ slave_parameter.get('error_log') }}
{%- if prefer_gzip and not (slave_type == 'zope' and backend_url) %} {%- if not (slave_type == 'zope' and backend_url) %}
rewrite { rewrite {
regexp (.*)
{% if prefer_gzip %}
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip{uri} to /prefer-gzip{1}
{% else %}
to {1}
{% endif %}
} }
{%- endif %} {#- if prefer_gzip and not (slave_type == 'zope' and backend_url) #} {%- endif %} {#- if not (slave_type == 'zope' and backend_url) #}
{%- if slave_type == 'zope' and backend_url %} {%- if slave_type == 'zope' and backend_url %}
# Zope configuration # Zope configuration
...@@ -161,12 +166,17 @@ ...@@ -161,12 +166,17 @@
log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}" log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}"
errors {{ slave_parameter.get('error_log') }} errors {{ slave_parameter.get('error_log') }}
{%- if prefer_gzip and not (slave_type == 'zope' and backend_url) %} {%- if not (slave_type == 'zope' and backend_url) %}
rewrite { rewrite {
regexp (.*)
{%- if prefer_gzip %}
if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
to /prefer-gzip{uri} to /prefer-gzip{1}
{% else %}
to {1}
{% endif %}
} }
{%- endif %} {#- if prefer_gzip and not (slave_type == 'zope' and backend_url) #} {%- endif %} {#- if not (slave_type == 'zope' and backend_url) #}
{%- if https_only %} {%- if https_only %}
# Enforced redirection to SSL-enabled host # Enforced redirection to SSL-enabled host
......
...@@ -1147,13 +1147,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1147,13 +1147,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
try: try:
j = result.json() j = result.json()
...@@ -1172,8 +1173,9 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1172,8 +1173,9 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result_http = self.fakeHTTPResult( result_http = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
self.assertEqualResultJson(result_http, 'Path', '/test-path') 'test-path/deep/.././deeper')
self.assertEqualResultJson(result_http, 'Path', '/test-path/deeper')
try: try:
j = result_http.json() j = result_http.json()
...@@ -1238,7 +1240,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1238,7 +1240,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
...@@ -1248,7 +1251,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1248,7 +1251,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
result, result,
'Path', 'Path',
'/VirtualHostBase/https//' '/VirtualHostBase/https//'
'typezopepath.example.com:443/path/VirtualHostRoot/test-path' 'typezopepath.example.com:443/path/VirtualHostRoot/test-path/deeper'
) )
def test_type_zope_default_path(self): def test_type_zope_default_path(self):
...@@ -1295,25 +1298,28 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1295,25 +1298,28 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
'alias1.example.com', parameter_dict['public-ipv4'], 'test-path') 'alias1.example.com', parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
'alias2.example.com', parameter_dict['public-ipv4'], 'test-path') 'alias2.example.com', parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
...@@ -1511,19 +1517,21 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1511,19 +1517,21 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
result_http = self.fakeHTTPResult( result_http = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
'https://httpsonly.example.com/test-path', 'https://httpsonly.example.com/test-path/deeper',
result_http.headers['Location'] result_http.headers['Location']
) )
...@@ -1617,7 +1625,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1617,7 +1625,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
...@@ -1633,17 +1642,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1633,17 +1642,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
result, result,
'Path', 'Path',
'/VirtualHostBase/https//typezope.example.com:443/' '/VirtualHostBase/https//typezope.example.com:443/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
result = self.fakeHTTPResult( result = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqualResultJson( self.assertEqualResultJson(
result, result,
'Path', 'Path',
'/VirtualHostBase/http//typezope.example.com:80/' '/VirtualHostBase/http//typezope.example.com:80/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
def test_type_zope_prefer_gzip_encoding_to_backend(self): def test_type_zope_prefer_gzip_encoding_to_backend(self):
...@@ -1664,7 +1674,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1664,7 +1674,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
...@@ -1681,22 +1692,24 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1681,22 +1692,24 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
'Path', 'Path',
'/VirtualHostBase/https//' '/VirtualHostBase/https//'
'typezopeprefergzipencodingtobackend.example.com:443/' 'typezopeprefergzipencodingtobackend.example.com:443/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
result = self.fakeHTTPResult( result = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqualResultJson( self.assertEqualResultJson(
result, result,
'Path', 'Path',
'/VirtualHostBase/http//' '/VirtualHostBase/http//'
'typezopeprefergzipencodingtobackend.example.com:80/' 'typezopeprefergzipencodingtobackend.example.com:80/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path', parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper',
headers={'Accept-Encoding': 'gzip, deflate'}) headers={'Accept-Encoding': 'gzip, deflate'})
self.assertEqual( self.assertEqual(
...@@ -1714,13 +1727,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1714,13 +1727,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
'Path', 'Path',
'/VirtualHostBase/https//' '/VirtualHostBase/https//'
'typezopeprefergzipencodingtobackend.example.com:443/' 'typezopeprefergzipencodingtobackend.example.com:443/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
self.assertEqual( self.assertEqual(
'gzip', result.json()['Incoming Headers']['accept-encoding']) 'gzip', result.json()['Incoming Headers']['accept-encoding'])
result = self.fakeHTTPResult( result = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path', parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper',
headers={'Accept-Encoding': 'gzip, deflate'}) headers={'Accept-Encoding': 'gzip, deflate'})
self.assertEqualResultJson( self.assertEqualResultJson(
...@@ -1728,7 +1742,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1728,7 +1742,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
'Path', 'Path',
'/VirtualHostBase/http//' '/VirtualHostBase/http//'
'typezopeprefergzipencodingtobackend.example.com:80/' 'typezopeprefergzipencodingtobackend.example.com:80/'
'/VirtualHostRoot/test-path' '/VirtualHostRoot/test-path/deeper'
) )
self.assertEqual( self.assertEqual(
'gzip', result.json()['Incoming Headers']['accept-encoding']) 'gzip', result.json()['Incoming Headers']['accept-encoding'])
...@@ -1807,14 +1821,15 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1807,14 +1821,15 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path', parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper',
NGINX_HTTPS_PORT) NGINX_HTTPS_PORT)
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
@skip('Feature postponed') @skip('Feature postponed')
def test_type_websocket(self): def test_type_websocket(self):
...@@ -1889,14 +1904,15 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1889,14 +1904,15 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqual( self.assertEqual(
'%s/test-path' % (self.backend_url,), '%s/test-path/deeper' % (self.backend_url,),
result.headers['Location'] result.headers['Location']
) )
...@@ -2052,7 +2068,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2052,7 +2068,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
...@@ -2064,7 +2081,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2064,7 +2081,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result_http = self.fakeHTTPResult( result_http = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deeper')
self.assertEqual( self.assertEqual(
httplib.BAD_GATEWAY, httplib.BAD_GATEWAY,
...@@ -2091,13 +2109,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2091,13 +2109,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
headers = result.headers.copy() headers = result.headers.copy()
...@@ -2458,13 +2477,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2458,13 +2477,14 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
headers = result.headers.copy() headers = result.headers.copy()
...@@ -2746,40 +2766,44 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2746,40 +2766,44 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path', parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper',
headers={'Accept-Encoding': 'gzip, deflate'}) headers={'Accept-Encoding': 'gzip, deflate'})
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
self.assertEqual( self.assertEqual(
'gzip', result.json()['Incoming Headers']['accept-encoding']) 'gzip', result.json()['Incoming Headers']['accept-encoding'])
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path', parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper',
headers={'Accept-Encoding': 'deflate'}) headers={'Accept-Encoding': 'deflate'})
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
self.assertEqual( self.assertEqual(
'deflate', result.json()['Incoming Headers']['accept-encoding']) 'deflate', result.json()['Incoming Headers']['accept-encoding'])
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqualResultJson(result, 'Path', '/test-path') self.assertEqualResultJson(result, 'Path', '/test-path/deeper')
def test_disabled_cookie_list(self): def test_disabled_cookie_list(self):
parameter_dict = self.parseSlaveParameterDict('disabled-cookie-list') parameter_dict = self.parseSlaveParameterDict('disabled-cookie-list')
...@@ -3004,17 +3028,19 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -3004,17 +3028,19 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
result = self.fakeHTTPSResult( result = self.fakeHTTPSResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
'test-path/deep/.././deeper')
self.assertEqual( self.assertEqual(
self.certificate_pem, self.certificate_pem,
der2pem(result.peercert)) der2pem(result.peercert))
self.assertEqualResultJson(result, 'Path', '/https/test-path') self.assertEqualResultJson(result, 'Path', '/https/test-path/deeper')
result_http = self.fakeHTTPResult( result_http = self.fakeHTTPResult(
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'],
self.assertEqualResultJson(result_http, 'Path', '/http/test-path') 'test-path/deep/.././deeper')
self.assertEqualResultJson(result_http, 'Path', '/http/test-path/deeper')
class TestReplicateSlave(SlaveHttpFrontendTestCase, TestDataMixin): class TestReplicateSlave(SlaveHttpFrontendTestCase, TestDataMixin):
......
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