MCPcopy
hub / github.com/pallets/werkzeug / get_current_url

Function get_current_url

src/werkzeug/wsgi.py:31–66  ·  view source on GitHub ↗

Recreate the URL for a request from the parts in a WSGI environment. The URL is an IRI, not a URI, so it may contain Unicode characters. Use :func:`~werkzeug.urls.iri_to_uri` to convert it to ASCII. :param environ: The WSGI environment to get the URL parts from. :param root_onl

(
    environ: WSGIEnvironment,
    root_only: bool = False,
    strip_querystring: bool = False,
    host_only: bool = False,
    trusted_hosts: t.Collection[str] | None = None,
)

Source from the content-addressed store, hash-verified

29
30
31def get_current_url(
32 environ: WSGIEnvironment,
33 root_only: bool = False,
34 strip_querystring: bool = False,
35 host_only: bool = False,
36 trusted_hosts: t.Collection[str] | None = None,
37) -> str:
38 """Recreate the URL for a request from the parts in a WSGI
39 environment.
40
41 The URL is an IRI, not a URI, so it may contain Unicode characters.
42 Use :func:`~werkzeug.urls.iri_to_uri` to convert it to ASCII.
43
44 :param environ: The WSGI environment to get the URL parts from.
45 :param root_only: Only build the root path, don't include the
46 remaining path or query string.
47 :param strip_querystring: Don't include the query string.
48 :param host_only: Only build the scheme and host.
49 :param trusted_hosts: A list of trusted host names to validate the
50 host against.
51 """
52 parts = {
53 "scheme": environ["wsgi.url_scheme"],
54 "host": get_host(environ, trusted_hosts),
55 }
56
57 if not host_only:
58 parts["root_path"] = environ.get("SCRIPT_NAME", "")
59
60 if not root_only:
61 parts["path"] = environ.get("PATH_INFO", "")
62
63 if not strip_querystring:
64 parts["query_string"] = environ.get("QUERY_STRING", "").encode("latin1")
65
66 return _sansio_utils.get_current_url(**parts)
67
68
69def _get_server(

Callers 2

_add_cookies_to_wsgiMethod · 0.70
run_wsgi_appMethod · 0.70

Calls 2

get_hostFunction · 0.70
getMethod · 0.45

Tested by 2

_add_cookies_to_wsgiMethod · 0.56
run_wsgi_appMethod · 0.56