#7 validate port number

This commit is contained in:
Michael Lazar 2020-01-12 18:24:04 -05:00
parent c5d5c8d472
commit 416c7bcecf
1 changed files with 6 additions and 0 deletions

View File

@ -118,7 +118,9 @@ class RoutePattern:
path: str = "" path: str = ""
scheme: str = "gemini" scheme: str = "gemini"
strict_hostname: bool = True strict_hostname: bool = True
strict_port: bool = True
strict_trailing_slash: bool = False strict_trailing_slash: bool = False
def match(self, request: Request) -> bool: def match(self, request: Request) -> bool:
@ -126,9 +128,13 @@ class RoutePattern:
Check if the given request URL matches this route pattern. Check if the given request URL matches this route pattern.
""" """
server_hostname = request.environ["HOSTNAME"] server_hostname = request.environ["HOSTNAME"]
server_port = int(request.environ["SERVER_PORT"])
if self.strict_hostname and request.hostname != server_hostname: if self.strict_hostname and request.hostname != server_hostname:
return False return False
if self.strict_port and request.port is not None:
if request.port != server_port:
return False
if self.scheme and self.scheme != request.scheme: if self.scheme and self.scheme != request.scheme:
return False return False