tribler.core.restapi.rest_manager ================================= .. py:module:: tribler.core.restapi.rest_manager Attributes ---------- .. autoapisummary:: tribler.core.restapi.rest_manager.ComponentsType tribler.core.restapi.rest_manager.logger tribler.core.restapi.rest_manager.RESTEndpointType Classes ------- .. autoapisummary:: tribler.core.restapi.rest_manager.ApiKeyMiddleware tribler.core.restapi.rest_manager.RESTManager Functions --------- .. autoapisummary:: tribler.core.restapi.rest_manager.wrap_tcp_keepalive tribler.core.restapi.rest_manager.error_middleware tribler.core.restapi.rest_manager.ui_middleware tribler.core.restapi.rest_manager.required_components_middleware Module Contents --------------- .. py:data:: ComponentsType .. py:data:: logger .. py:data:: RESTEndpointType .. py:function:: wrap_tcp_keepalive(transport: asyncio.Transport) -> None A wrapper around aiohttp's tcp_keepalive that catches OSError 22 instances. See https://github.com/Tribler/tribler/issues/6429 .. py:class:: ApiKeyMiddleware(api_key: str) Middleware to check if REST requests include an API key. The key can be in: - The ``X-Api-Key`` header. - The ``apikey`` query parameter. - The ``api_key`` cookie. .. py:attribute:: api_key .. py:method:: __call__(request: aiohttp.web_request.Request, handler: collections.abc.Callable[[aiohttp.web_request.Request], collections.abc.Awaitable[tribler.core.restapi.rest_endpoint.RESTResponse]]) -> tribler.core.restapi.rest_endpoint.RESTResponse :async: Call this middleware. .. py:method:: authenticate(request: aiohttp.web_request.Request) -> bool Is the given request authenticated using an API key. .. py:function:: error_middleware(request: aiohttp.web_request.Request, handler: collections.abc.Callable[[aiohttp.web_request.Request], collections.abc.Awaitable[tribler.core.restapi.rest_endpoint.RESTResponse]]) -> tribler.core.restapi.rest_endpoint.RESTResponse :async: Middleware to return nicely-formatted errors when common exceptions occur. .. py:function:: ui_middleware(request: aiohttp.web_request.Request, handler: collections.abc.Callable[[aiohttp.web_request.Request], collections.abc.Awaitable[tribler.core.restapi.rest_endpoint.RESTResponse]]) -> tribler.core.restapi.rest_endpoint.RESTResponse :async: Forward request to a unknown pathname to /ui. This enables the GUI to request e.g. /index.html instead of using /ui/index.html. .. py:function:: required_components_middleware(request: aiohttp.web_request.Request, handler: collections.abc.Callable[[aiohttp.web_request.Request], collections.abc.Awaitable[tribler.core.restapi.rest_endpoint.RESTResponse]]) -> tribler.core.restapi.rest_endpoint.RESTResponse :async: Read a handler's required components and return HTTP_NOT_FOUND if they have not been set (yet). .. py:class:: RESTManager(config: tribler.tribler_config.TriblerConfigManager, shutdown_timeout: int = 1) This class is responsible for managing the startup and closing of the Tribler HTTP API. .. py:attribute:: _logger .. py:attribute:: root_endpoint .. py:attribute:: runner :type: aiohttp.web.AppRunner | None :value: None .. py:attribute:: site :type: aiohttp.web.TCPSite | None :value: None .. py:attribute:: site_https :type: aiohttp.web.TCPSite | None :value: None .. py:attribute:: config .. py:attribute:: state_dir .. py:attribute:: http_host .. py:attribute:: https_host .. py:attribute:: shutdown_timeout :value: 1 .. py:method:: add_endpoint(endpoint: RESTEndpointType) -> RESTEndpointType Add a REST endpoint to the root endpoint. .. py:method:: get_endpoint(name: str) -> tribler.core.restapi.rest_endpoint.RESTEndpoint Get an endpoint by its name, including the first forward slash. Requesting a non-Tribler (i.e., IPv8) endpoint will cause a crash. .. py:method:: get_api_port() -> int | None Get the API port of the currently running server. .. py:method:: start() -> None :async: Starts the HTTP API with the listen port as specified in the session configuration. .. py:method:: start_http_site(runner: aiohttp.web.AppRunner) -> None :async: Start serving HTTP requests. .. py:method:: start_https_site(runner: aiohttp.web.AppRunner) -> None :async: Start serving HTTPS requests. .. py:method:: stop() -> None :async: Clean up all the REST endpoints and connections.