Skip to content

Commit

Permalink
Silently upgrade http to https for tile server urls
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 6, 2024
1 parent 787e5ee commit 32c6f62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions felt/core/layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ def layer_import_url(layer: QgsMapLayer) -> Optional[str]:
ds.setEncodedUri(layer.source())
if ds.param('type') == 'xyz':
url = ds.param('url')
if '{q}' not in url:
return url
if '{q}' in url:
return None
# older QGIS projects can use http eg for OSM servers,
# silently upgrade to https
url = url.replace('http://', 'https://')
return url

return None

Expand Down
11 changes: 11 additions & 0 deletions felt/test/test_layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ def test_use_url_import_method(self):
'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
)

# test http -> https upgrade
layer = QgsRasterLayer(
'crs=EPSG:3857&format&type=xyz&url='
'http://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png'
'&zmax=19&zmin=0',
'test', 'wms')
self.assertEqual(
LayerExporter.layer_import_url(layer),
'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
)

layer = QgsRasterLayer(
'http-header:referer=&type=xyz&url=http://ecn.t3.tiles.'
'virtualearth.net/tiles/a%7Bq%7D.jpeg?g%3D1&zmax=18&zmin=0',
Expand Down

0 comments on commit 32c6f62

Please sign in to comment.