Skip to content

Commit d634039

Browse files
committed
Rework to only replace first instance of path
1 parent b6cbc81 commit d634039

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/stac_auth_proxy/middleware/ProcessLinksMiddleware.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
5353
continue
5454

5555
# Remove the upstream_url path from the link if it exists
56-
if urlparse(self.upstream_url).path != "/":
56+
parsed_upstream_url = urlparse(self.upstream_url)
57+
if parsed_upstream_url.path != "/" and parsed_link.path.startswith(
58+
parsed_upstream_url.path
59+
):
5760
parsed_link = parsed_link._replace(
58-
path=str(parsed_link.path).replace(
59-
str(urlparse(self.upstream_url).path), ""
60-
)
61+
path=parsed_link.path[len(parsed_upstream_url.path) :]
6162
)
6263

6364
# Add the root_path to the link if it exists

0 commit comments

Comments
 (0)