Skip to content

Commit

Permalink
code comments adjusted as proposed in review
Browse files Browse the repository at this point in the history
  • Loading branch information
dhofstetter committed May 21, 2024
1 parent 404206f commit 1970a3f
Showing 1 changed file with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,12 @@ def get_host_port_url_tuple(scope):
server = scope.get("server") or ["0.0.0.0", 80]
port = server[1]
server_host = server[0] + (":" + str(port) if str(port) != "80" else "")
# To get the correct virtual url path within the hosting application (e.g also in a subapplication scenario)
# we have to remove the root_path from the path
# see:
# using the scope path is enough, see:
# - https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope (see: root_path and path)
# - https://asgi.readthedocs.io/en/latest/specs/www.html#wsgi-compatibility (see: PATH_INFO)
# PATH_INFO can be derived by stripping root_path from path
# -> that means that the path should contain the root_path already, so prefixing it again is not necessary
# - https://wsgi.readthedocs.io/en/latest/definitions.html#envvar-PATH_INFO
#
# From investigation it seems (that at least for fastapi), the path is already correctly set. That means
# that root_path is already included in the path, so we can use it directly for full path.
# old way: full_path = scope.get("root_path", "") + scope.get("path", "")
full_path = scope.get("path", "")
http_url = scope.get("scheme", "http") + "://" + server_host + full_path
return server_host, port, http_url
Expand Down

0 comments on commit 1970a3f

Please sign in to comment.