panel.io.proxy module#

Resolves the URL a server is reachable on from the outside when it runs behind a reverse proxy, which request handlers need to build redirects that lead back through the proxy.

panel.io.proxy.external_path(handler: RequestHandler, path: str) → str[source]#

Maps a path as the server received it to the path the client requested. Requests reaching the server through an ASGI root path already include it.

panel.io.proxy.external_url(handler: RequestHandler) → str[source]#

The URL the server root is reachable on from the outside, without a trailing slash.

panel.io.proxy.forwarded_host(headers: Mapping[str, str]) → str | None[source]#

The host the client addressed, as declared by the X-Forwarded-Host header, or None if it is missing or not a valid host.

panel.io.proxy.forwarded_prefix(headers: Mapping[str, str]) → str[source]#

The path prefix a proxy stripped off the request, as declared by the X-Forwarded-Prefix or X-Script-Name header. Values that are not a plain absolute path are ignored.

panel.io.proxy.forwarded_proto(headers: Mapping[str, str]) → str | None[source]#

The protocol the client used, as declared by the X-Forwarded-Proto header, or None if it is missing or neither http nor https.

panel.io.proxy.login_redirect_url(handler: RequestHandler, login_url: str) → str[source]#

The URL to send an unauthenticated request to. It is relative to the request, so that it is valid whether the request was proxied or not, unless the request is known to have come through a proxy serving the server on a root path. The absolute URL returned in that case is also correct if the proxy dropped a trailing slash.

panel.io.proxy.normalize_root_path(root_path: str | None) → str[source]#

Returns the root path with a leading and without a trailing slash, or an empty string if the server is served on the root.

panel.io.proxy.relative_url(path: str, target: str) → str[source]#

The relative reference which resolves to the target path from a document at path. Unlike an absolute path it stays valid behind a proxy which strips a path prefix the server does not know about.

panel.io.proxy.root_path(handler: RequestHandler) → str[source]#

The path the proxy serves the server on, without a trailing slash. An explicitly configured root path wins over the one a proxy declares, which is only trusted if xheaders are enabled.

panel.io.proxy.server_path(handler: RequestHandler) → str[source]#

The external path of the server root, i.e. the proxy root path followed by the server prefix, without a trailing slash.

panel.io.proxy.uses_xheaders(handler: RequestHandler) → bool[source]#

Whether the server was told to trust the headers set by a proxy.