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

Function get_current_url

src/werkzeug/sansio/utils.py:159–199  ·  view source on GitHub ↗

Recreate the URL for a request. If an optional part isn't provided, it and subsequent parts are not included in the URL. 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 scheme: The protocol the

(
    scheme: str,
    host: str,
    root_path: str | None = None,
    path: str | None = None,
    query_string: bytes | None = None,
)

Source from the content-addressed store, hash-verified

157
158
159def get_current_url(
160 scheme: str,
161 host: str,
162 root_path: str | None = None,
163 path: str | None = None,
164 query_string: bytes | None = None,
165) -> str:
166 """Recreate the URL for a request. If an optional part isn't
167 provided, it and subsequent parts are not included in the URL.
168
169 The URL is an IRI, not a URI, so it may contain Unicode characters.
170 Use :func:`~werkzeug.urls.iri_to_uri` to convert it to ASCII.
171
172 :param scheme: The protocol the request used, like ``"https"``.
173 :param host: The host the request was made to. See :func:`get_host`.
174 :param root_path: Prefix that the application is mounted under. This
175 is prepended to ``path``.
176 :param path: The path part of the URL after ``root_path``.
177 :param query_string: The portion of the URL after the "?".
178 """
179 url = [scheme, "://", host]
180
181 if root_path is None:
182 url.append("/")
183 return uri_to_iri("".join(url))
184
185 # safe = https://url.spec.whatwg.org/#url-path-segment-string
186 # as well as percent for things that are already quoted
187 url.append(quote(root_path.rstrip("/"), safe="!$&'()*+,/:;=@%"))
188 url.append("/")
189
190 if path is None:
191 return uri_to_iri("".join(url))
192
193 url.append(quote(path.lstrip("/"), safe="!$&'()*+,/:;=@%"))
194
195 if query_string:
196 url.append("?")
197 url.append(quote(query_string, safe="!$&'()*+,/:;=?@%"))
198
199 return uri_to_iri("".join(url))
200
201
202def get_content_length(

Callers 5

urlMethod · 0.70
base_urlMethod · 0.70
root_urlMethod · 0.70
host_urlMethod · 0.70
get_wsgi_headersMethod · 0.50

Calls 2

uri_to_iriFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected