tribler.core.restapi.rest_manager
Attributes
Classes
Middleware to check if REST requests include an API key. |
|
This class is responsible for managing the startup and closing of the Tribler HTTP API. |
Functions
|
A wrapper around aiohttp's tcp_keepalive that catches OSError 22 instances. |
|
Middleware to return nicely-formatted errors when common exceptions occur. |
|
Forward request to a unknown pathname to /ui. |
Read a handler's required components and return HTTP_NOT_FOUND if they have not been set (yet). |
Module Contents
- tribler.core.restapi.rest_manager.ComponentsType
- tribler.core.restapi.rest_manager.logger
- tribler.core.restapi.rest_manager.RESTEndpointType
- tribler.core.restapi.rest_manager.wrap_tcp_keepalive(transport: asyncio.Transport) None
A wrapper around aiohttp’s tcp_keepalive that catches OSError 22 instances.
- class tribler.core.restapi.rest_manager.ApiKeyMiddleware(api_key: str)
Middleware to check if REST requests include an API key.
The key can be in:
The
X-Api-Keyheader.The
apikeyquery parameter.The
api_keycookie.
- api_key
- async __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
Call this middleware.
- async tribler.core.restapi.rest_manager.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
Middleware to return nicely-formatted errors when common exceptions occur.
- async tribler.core.restapi.rest_manager.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
Forward request to a unknown pathname to /ui. This enables the GUI to request e.g. /index.html instead of using /ui/index.html.
- async tribler.core.restapi.rest_manager.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
Read a handler’s required components and return HTTP_NOT_FOUND if they have not been set (yet).
- class tribler.core.restapi.rest_manager.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.
- _logger
- root_endpoint
- config
- state_dir
- http_host
- https_host
- shutdown_timeout = 1
- add_endpoint(endpoint: RESTEndpointType) RESTEndpointType
Add a REST endpoint to the root endpoint.
- 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.