Skip to content

Commit

Permalink
compare parameters in lowercase (#323)
Browse files Browse the repository at this point in the history
* compare parameters in lowercase

* update changelog
  • Loading branch information
vincentsarago authored Jun 3, 2021
1 parent e1f02f9 commit 4ef776e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Notes

## Next (TBD)

### titiler.core

* fix possible bug when querystring parameter are case insensitive (https://github.com/developmentseed/titiler/pull/323)

### titiler.mosaic

* update `tilejson` and `WMTSCapabilities.xml` endpoints to allow list querystrings (as done previously in https://github.com/developmentseed/titiler/issues/319)

## 0.3.2 (2021-05-26)

### titiler.core
Expand Down
10 changes: 10 additions & 0 deletions titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ def test_TilerFactory():
assert response.headers["content-type"] == "application/json"
assert response.json()["tilejson"]

response = client.get(f"/WorldCRS84Quad/tilejson.json?url={DATA_DIR}/cog.tif")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
assert response.json()["tilejson"]

response_qs = client.get(
f"/tilejson.json?url={DATA_DIR}/cog.tif&TileMatrixSetId=WorldCRS84Quad"
)
assert response.json()["tiles"] == response_qs.json()["tiles"]

response = client.get(f"/tilejson.json?url={DATA_DIR}/cog.tif&tile_format=png")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
Expand Down
12 changes: 6 additions & 6 deletions titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def tilejson(
tiles_url = self.url_for(request, "tile", **route_params)

qs_key_to_remove = [
"TileMatrixSetIt",
"tilematrixsetid",
"tile_format",
"tile_scale",
"minzoom",
Expand All @@ -420,7 +420,7 @@ def tilejson(
qs = [
(key, value)
for (key, value) in request.query_params._list
if key not in qs_key_to_remove
if key.lower() not in qs_key_to_remove
]
if qs:
tiles_url += f"?{urlencode(qs)}"
Expand Down Expand Up @@ -482,18 +482,18 @@ def wmts(
tiles_url = self.url_for(request, "tile", **route_params)

qs_key_to_remove = [
"TileMatrixSetIt",
"tilematrixsetid",
"tile_format",
"tile_scale",
"minzoom",
"maxzoom",
"SERVICE",
"REQUEST",
"service",
"request",
]
qs = [
(key, value)
for (key, value) in request.query_params._list
if key not in qs_key_to_remove
if key.lower() not in qs_key_to_remove
]
if qs:
tiles_url += f"?{urlencode(qs)}"
Expand Down
20 changes: 20 additions & 0 deletions titiler/mosaic/tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ def test_MosaicTilerFactory():
assert body["minzoom"] == 6
assert body["maxzoom"] == 9

response = client.get(
"/mosaic/tilejson.json",
params={
"url": mosaic_file,
"tile_format": "png",
"minzoom": 6,
"maxzoom": 9,
"TileMatrixSetId": "WebMercatorQuad",
},
)
assert response.status_code == 200
body = response.json()
assert (
"http://testserver/mosaic/tiles/WebMercatorQuad/{z}/{x}/{y}@1x.png?url="
in body["tiles"][0]
)
assert body["minzoom"] == 6
assert body["maxzoom"] == 9
assert "TileMatrixSetId" not in body["tiles"][0]

response = client.get(
"/mosaic/WMTSCapabilities.xml",
params={
Expand Down
48 changes: 30 additions & 18 deletions titiler/mosaic/titiler/mosaic/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,20 @@ def tilejson(
route_params["format"] = tile_format.value
tiles_url = self.url_for(request, "tile", **route_params)

q = dict(request.query_params)
q.pop("TileMatrixSetId", None)
q.pop("tile_format", None)
q.pop("tile_scale", None)
q.pop("minzoom", None)
q.pop("maxzoom", None)
qs = urlencode(list(q.items()))
tiles_url += f"?{qs}"
qs_key_to_remove = [
"tilematrixsetid",
"tile_format",
"tile_scale",
"minzoom",
"maxzoom",
]
qs = [
(key, value)
for (key, value) in request.query_params._list
if key.lower() not in qs_key_to_remove
]
if qs:
tiles_url += f"?{urlencode(qs)}"

with self.reader(src_path, **self.backend_options) as src_dst:
center = list(src_dst.center)
Expand Down Expand Up @@ -369,16 +375,22 @@ def wmts(
}
tiles_url = self.url_for(request, "tile", **route_params)

q = dict(request.query_params)
q.pop("TileMatrixSetId", None)
q.pop("tile_format", None)
q.pop("tile_scale", None)
q.pop("minzoom", None)
q.pop("maxzoom", None)
q.pop("SERVICE", None)
q.pop("REQUEST", None)
qs = urlencode(list(q.items()))
tiles_url += f"?{qs}"
qs_key_to_remove = [
"tilematrixsetid",
"tile_format",
"tile_scale",
"minzoom",
"maxzoom",
"service",
"request",
]
qs = [
(key, value)
for (key, value) in request.query_params._list
if key.lower() not in qs_key_to_remove
]
if qs:
tiles_url += f"?{urlencode(qs)}"

with self.reader(src_path, **self.backend_options) as src_dst:
bounds = src_dst.bounds
Expand Down

0 comments on commit 4ef776e

Please sign in to comment.