Skip to content

Commit

Permalink
Merge db640ce into 4183dde
Browse files Browse the repository at this point in the history
  • Loading branch information
vancamti committed Mar 28, 2023
2 parents 4183dde + db640ce commit 8bca845
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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 8bca845

Please sign in to comment.