Skip to content

Commit

Permalink
Use X-Forwarded-* for server netloc when available
Browse files Browse the repository at this point in the history
Closes Kozea#1271
  • Loading branch information
Unrud committed Mar 8, 2023
1 parent 1a78114 commit 360484e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions radicale/app/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@


def get_server_netloc(environ: types.WSGIEnviron, force_port: bool = False):
host = environ.get("HTTP_HOST") or environ["SERVER_NAME"]
proto = environ["wsgi.url_scheme"]
port = environ["SERVER_PORT"]
if environ.get("HTTP_X_FORWARDED_HOST"):
host = environ["HTTP_X_FORWARDED_HOST"]
proto = environ.get("HTTP_X_FORWARDED_PROTO") or "http"
port = "443" if proto == "https" else "80"
else:
host = environ.get("HTTP_HOST") or environ["SERVER_NAME"]
proto = environ["wsgi.url_scheme"]
port = environ["SERVER_PORT"]
if (not force_port and port == ("443" if proto == "https" else "80") or
re.search(r":\d+$", host)):
return host
Expand Down

0 comments on commit 360484e

Please sign in to comment.