Skip to content

Commit

Permalink
Merge pull request #247 from arnaud-morvan/apache_dimensions_regex
Browse files Browse the repository at this point in the history
Reorder parameters in apache rewrite rule and add + sign in token regex
  • Loading branch information
sbrunner committed Feb 29, 2016
2 parents 88014f1 + 3f13ecf commit 6678caa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
23 changes: 17 additions & 6 deletions tilecloud_chain/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def _generate_apache_config(gene):
if not gene.validate_mapcache_config():
exit(1) # pragma: no cover
if use_mapcache and not use_server:
token_regex = '([a-zA-Z0-9_\-\+~\.]+)'
f.write('\n')
for l in gene.config['layers']:
layer = gene.config['layers'][l]
Expand All @@ -387,15 +388,25 @@ def _generate_apache_config(gene):
dim = len(layer['dimensions'])
for r in res:
f.write(
'RewriteRule ^%(tiles_location)s/1.0.0/%(layer)s/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/'
'%(dimensions_re)s%(zoom)s/(.*)$ %(mapcache_location)s/wmts/1.0.0/%(layer)s/$1/$2/'
'%(dimensions_rep)s%(zoom)s/%(final)s [PT]\n' % {
'RewriteRule'
' '
'^%(tiles_location)s/1.0.0/%(layer)s/%(token_regex)s' # Baseurl/layer/Style
'%(dimensions_re)s' # Dimensions : variable number of values
'/%(token_regex)s/%(zoom)s/(.*)$' # TileMatrixSet/TileMatrix/TileRow/TileCol.extension
' '
'%(mapcache_location)s/wmts/1.0.0/%(layer)s/$1'
'%(dimensions_rep)s'
'/$%(tilematrixset)s/%(zoom)s/$%(final)s'
' '
'[PT]\n' % {
'tiles_location': gene.config['apache']['location'],
'mapcache_location': gene.config['mapcache']['location'],
'layer': layer['name'],
'dimensions_re': ''.join(['([a-zA-Z0-9_\-~\.]+)/' for e in range(dim)]),
'dimensions_rep': ''.join(['$%i/' % (e + 3) for e in range(dim)]),
'final': '$%i' % (3 + dim),
'token_regex': token_regex,
'dimensions_re': ''.join(['/' + token_regex for e in range(dim)]),
'dimensions_rep': ''.join(['/$%i' % (e + 2) for e in range(dim)]),
'tilematrixset': dim + 2,
'final': dim + 3,
'zoom': layer['grid_ref']['resolutions'].index(r)
}
)
Expand Down
10 changes: 5 additions & 5 deletions tilecloud_chain/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,9 @@ def test_apache(self):
Alias /tiles /tmp/tiles/
RewriteRule ^/tiles/1.0.0/point_hash/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/4/(.*)$ """
RewriteRule ^/tiles/1.0.0/point_hash/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/4/(.*)$ """
"""/mapcache/wmts/1.0.0/point_hash/$1/$2/$3/4/$4 [PT]
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/4/(.*)$ """
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/4/(.*)$ """
"""/mapcache/wmts/1.0.0/point/$1/$2/$3/4/$4 [PT]
MapCacheAlias /mapcache "%s"
Expand Down Expand Up @@ -1535,9 +1535,9 @@ def test_apache_s3(self):
ProxyPass /tiles/ http://s3-eu-west-1.amazonaws.com/tiles/tiles/
ProxyPassReverse /tiles/ http://s3-eu-west-1.amazonaws.com/tiles/tiles/
RewriteRule ^/tiles/1.0.0/point_hash/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/4/(.*)$ """
RewriteRule ^/tiles/1.0.0/point_hash/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/4/(.*)$ """
"""/mapcache/wmts/1.0.0/point_hash/$1/$2/$3/4/$4 [PT]
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/4/(.*)$ """
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/4/(.*)$ """
"""/mapcache/wmts/1.0.0/point/$1/$2/$3/4/$4 [PT]
MapCacheAlias /mapcache "%s"
Expand Down Expand Up @@ -1567,7 +1567,7 @@ def test_apache_s3_tilesurl(self):
ProxyPass /tiles/ http://tiles.example.com/
ProxyPassReverse /tiles/ http://tiles.example.com/
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-~\.]+)/([a-zA-Z0-9_\-~\.]+)/4/(.*)$ """
RewriteRule ^/tiles/1.0.0/point/([a-zA-Z0-9_\-\+~\.]+)/([a-zA-Z0-9_\-\+~\.]+)/4/(.*)$ """
"""/mapcache/wmts/1.0.0/point/$1/$2/4/$3 [PT]
MapCacheAlias /mapcache "%s"
Expand Down

0 comments on commit 6678caa

Please sign in to comment.