Skip to content

Commit

Permalink
use integer regex
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Jan 16, 2025
1 parent 7d00a9a commit 156d416
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stac_fastapi/api/stac_fastapi/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
for proxy in forwarded.split(","):
if (proto_expr := re.search(r"proto=(?P<proto>http(s)?)", proxy)) and (
host_expr := re.search(
r"host=(?P<host>[\w.-]+)(:(?P<port>\w+))?", proxy
r"host=(?P<host>[\w.-]+)(:(?P<port>\d{1,5}))?", proxy
)
):
proto = proto_expr.groupdict()["proto"]
Expand All @@ -107,7 +107,7 @@ def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
port_str = self._get_header_value_by_name(scope, "x-forwarded-port", port)

try:
port = int(port_str) if port_str is not None else None
port = int(port_str) if port_str is not None else port
except ValueError:
# ignore ports that are not valid integers
pass
Expand Down

0 comments on commit 156d416

Please sign in to comment.