diff --git a/CHANGES.rst b/CHANGES.rst index 7947e51..d5403b0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,9 @@ -1.0.0 (27-02-2023) +1.2.0 (25-04-2023) +------------------ + +- URL parameters meegeven (#92) + +1.1.0 (27-02-2023) ------------------ - Onderscheid op accept header toelaten (#86) diff --git a/setup.py b/setup.py index b4b7c8d..77e98d6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="urihandler", - version="1.1.0", + version="1.2.0", description="A tiny application that handles (cool) uri's.", long_description=README + "\n\n" + CHANGES, classifiers=[ diff --git a/tests/test_functional.py b/tests/test_functional.py index ecc26d4..40b7ec5 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -65,6 +65,23 @@ def test_uris(self, app): assert data["uri"] == "http://localhost/foobar/18" assert data["location"] == "http://localhost:5555/foobar/18" + def test_uris_with_params(self, app): + res = app.get( + "/uris?uri=http://localhost/foobar/18" + "?utm_source%3Dbeslissingsmail%26utm_medium%3Demail" + ) + assert res.status == "200 OK" + assert "application/json" in res.headers["Content-Type"] + data = json.loads(res.body.decode("utf-8")) + assert data["uri"] == ( + "http://localhost/foobar/18" + "?utm_source=beslissingsmail&utm_medium=email" + ) + assert data["location"] == ( + "http://localhost:5555/foobar/18" + "?utm_source=beslissingsmail&utm_medium=email" + ) + def test_uris_no_match(self, app): res = app.get("/uris?uri=http://id.erfgoed.net/foo/1") assert res.status == "200 OK" diff --git a/urihandler/handler.py b/urihandler/handler.py index 5035da0..d4634db 100644 --- a/urihandler/handler.py +++ b/urihandler/handler.py @@ -22,6 +22,9 @@ def __init__(self, uris=[]): self.uris = uris def handle(self, uri, request): + params = "" + if "?" in uri: + uri, params = uri.split("?", 1) uris = copy.deepcopy(self.uris) for u in uris: if "mount" not in u or u["mount"]: @@ -37,7 +40,10 @@ def handle(self, uri, request): redirect = self._get_redirect_based_on_accept_header( request.accept, redirect ) - redirect = redirect.format(**m.groupdict()) + if params: + redirect = f"{redirect.format(**m.groupdict())}?{params}" + else: + redirect = redirect.format(**m.groupdict()) log.debug(f"Match found. Redirecting to {redirect}.") return redirect return None