archivebox.core.routes_util

Module Contents

Functions

split_host_port

_normalize_base_url

normalize_base_url

_csrf_trusted_origins

_allowed_hosts

derive_base_url_from_csrf

Pick a single CSRF_TRUSTED_ORIGINS entry to act as the implicit BASE_URL.

get_listen_host

get_listen_parts

_with_port

strip_role_subdomain

Strip leading admin. / web. / api. / public. / snap-*. labels from a host (preserving the port). Strips repeatedly so an already-compounded host like snap-X.snap-X.<base> reduces all the way down to <base>.

_is_local_bind_host

canonical_base_host_for_request

Strip role subdomains and remap loopback hostnames to archivebox.localhost.

_root_host_from_listen

get_base_url

get_base_host

_build_base_host

get_admin_host

get_web_host

get_api_host

get_public_host

get_snapshot_subdomain

get_snapshot_host

get_original_host

is_snapshot_subdomain

get_snapshot_lookup_key

get_listen_subdomain

host_matches

_scheme_from_request

_build_base_url_for_host

get_admin_base_url

get_web_base_url

get_api_base_url

get_public_base_url

get_snapshot_base_url

get_original_base_url

build_admin_url

build_web_url

build_snapshot_url

build_original_url

_build_url

Data

_SNAPSHOT_ID_RE

_SNAPSHOT_SUBDOMAIN_RE

_ROLE_SUBDOMAIN_LABELS

API

archivebox.core.routes_util._SNAPSHOT_ID_RE[source]

β€˜compile(…)’

archivebox.core.routes_util._SNAPSHOT_SUBDOMAIN_RE[source]

β€˜compile(…)’

archivebox.core.routes_util._ROLE_SUBDOMAIN_LABELS[source]

(β€˜admin’, β€˜web’, β€˜api’, β€˜public’)

archivebox.core.routes_util.split_host_port(host: str) tuple[str, str | None][source]
archivebox.core.routes_util._normalize_base_url(value: str | None) str[source]
archivebox.core.routes_util.normalize_base_url(value: str | None) str[source]
archivebox.core.routes_util._csrf_trusted_origins(config) list[str][source]
archivebox.core.routes_util._allowed_hosts(config) set[str][source]
archivebox.core.routes_util.derive_base_url_from_csrf(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]

Pick a single CSRF_TRUSTED_ORIGINS entry to act as the implicit BASE_URL.

0.7.3 β†’ 0.9.0 upgrade path: any reverse-proxied 0.7.3 deployment already had CSRF_TRUSTED_ORIGINS=https://archive.example.com set (required for admin login to work). On upgrade, BASE_URL is the new knob β€” but it defaults to empty, and falling through to BIND_ADDR produces an unreachable URL like http://0.0.0.0:8000. If the user has exactly one CSRF origin we treat it as the implicit BASE_URL so links/redirects keep pointing at the public hostname they already configured.

Returns "" when the inference is ambiguous (multiple origins) or impossible (none set) so callers fall through to their next strategy.

archivebox.core.routes_util.get_listen_host(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_listen_parts(config: dict[str, Any] | None = None, **config_kwargs: Any) tuple[str, str | None][source]
archivebox.core.routes_util._with_port(host: str, port: str | None) str[source]
archivebox.core.routes_util.strip_role_subdomain(host: str) str[source]

Strip leading admin. / web. / api. / public. / snap-*. labels from a host (preserving the port). Strips repeatedly so an already-compounded host like snap-X.snap-X.<base> reduces all the way down to <base>.

Used when we want to recover the canonical base host from a request that arrived on a role subdomain β€” otherwise builders that prepend their own role label (e.g. snap-X.) compound onto the existing prefix and you get snap-X.snap-X.snap-X.<base> on every click.

archivebox.core.routes_util._is_local_bind_host(host: str) bool[source]
archivebox.core.routes_util.canonical_base_host_for_request(request_host: str) str[source]

Strip role subdomains and remap loopback hostnames to archivebox.localhost.

Used by the banner suggestion and the in-browser pin endpoint: when the user is hitting the server on raw localhost:9292 or 127.0.0.1:9292 we want to suggest the wildcard-friendly archivebox.localhost family instead, so the eventual pinned BASE_URL plays nicely with subdomain routing without forcing the user to add a /etc/hosts entry.

archivebox.core.routes_util._root_host_from_listen(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_base_url(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_base_host(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util._build_base_host(subdomain: str | None, request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_admin_host(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_web_host(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_api_host(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_public_host(config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_snapshot_subdomain(snapshot_id: str) str[source]
archivebox.core.routes_util.get_snapshot_host(snapshot_id: str, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_original_host(domain: str, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.is_snapshot_subdomain(subdomain: str) bool[source]
archivebox.core.routes_util.get_snapshot_lookup_key(snapshot_ref: str) str[source]
archivebox.core.routes_util.get_listen_subdomain(request_host: str, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.host_matches(request_host: str, target_host: str) bool[source]
archivebox.core.routes_util._scheme_from_request(request=None, config: dict[str, Any] | None = None) str[source]
archivebox.core.routes_util._build_base_url_for_host(host: str, request=None, config: dict[str, Any] | None = None) str[source]
archivebox.core.routes_util.get_admin_base_url(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_web_base_url(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_api_base_url(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_public_base_url(request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_snapshot_base_url(snapshot_id: str, request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.get_original_base_url(domain: str, request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.build_admin_url(path: str = '', request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.build_web_url(path: str = '', request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.build_snapshot_url(snapshot_id: str, path: str = '', request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util.build_original_url(domain: str, path: str = '', request=None, config: dict[str, Any] | None = None, **config_kwargs: Any) str[source]
archivebox.core.routes_util._build_url(base_url: str, path: str) str[source]