Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silently upgrade http to https for tile server urls #81

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading