Skip to content

Commit b5d95f3

Browse files
vincentsaragolukasbindreiter
authored andcommitted
use integer regex
1 parent 2796d1c commit b5d95f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stac_fastapi/api/stac_fastapi/api/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
9494
for proxy in forwarded.split(","):
9595
if (proto_expr := re.search(r"proto=(?P<proto>http(s)?)", proxy)) and (
9696
host_expr := re.search(
97-
r"host=(?P<host>[\w.-]+)(:(?P<port>\w+))?", proxy
97+
r"host=(?P<host>[\w.-]+)(:(?P<port>\d{1,5}))?", proxy
9898
)
9999
):
100100
proto = proto_expr.groupdict()["proto"]
@@ -107,7 +107,7 @@ def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
107107
port_str = self._get_header_value_by_name(scope, "x-forwarded-port", port)
108108

109109
try:
110-
port = int(port_str) if port_str is not None else None
110+
port = int(port_str) if port_str is not None else port
111111
except ValueError:
112112
# ignore ports that are not valid integers
113113
pass

0 commit comments

Comments
 (0)