From aa9c93d42c15e48f67f8d313ad03e41dee3221e0 Mon Sep 17 00:00:00 2001 From: Richard Leyton Date: Fri, 1 Sep 2023 09:47:29 +0100 Subject: [PATCH] Handle comma separated x-forwarded-ports --- mangum/handlers/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mangum/handlers/utils.py b/mangum/handlers/utils.py index 7e3e7b3..43df93b 100644 --- a/mangum/handlers/utils.py +++ b/mangum/handlers/utils.py @@ -21,6 +21,11 @@ def get_server_and_port(headers: dict) -> Tuple[str, int]: server_port = headers.get("x-forwarded-port", 80) else: server_name, server_port = server_name.split(":") # pragma: no cover + + # If passing through additional proxies, can be comma-separated ports, so take the first + if "," in server_port: + server_port = server_port.split(",")[0] + server = (server_name, int(server_port)) return server