Skip to content

Commit

Permalink
Merge pull request #95 from OnroerendErfgoed/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JonasGe authored Apr 25, 2023
2 parents 3982ebc + 7dcd2b8 commit bfabf55
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
17 changes: 17 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion urihandler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand All @@ -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
Expand Down

0 comments on commit bfabf55

Please sign in to comment.