galaxy.http¶
This module standardizes http traffic and the error handling for further communication with the GOG Galaxy 2.0.
It is recommended to use provided convenient methods for HTTP requests, especially when dealing with authorized sessions. Exemplary simple web service could looks like:
from galaxy.http import create_client_session, handle_exception class BackendClient: AUTH_URL = 'my-integration.com/auth' HEADERS = { "My-Custom-Header": "true", } def __init__(self): self._session = create_client_session(headers=self.HEADERS) async def authenticate(self): await self._session.request('POST', self.AUTH_URL) async def close(self): # to be called on plugin shutdown await self._session.close() async def _authorized_request(self, method, url, *args, **kwargs): with handle_exceptions(): return await self._session.request(method, url, *args, **kwargs)
-
galaxy.http.
DEFAULT_LIMIT
= 20¶ Default limit of the simultaneous connections for ssl connector.
-
galaxy.http.
DEFAULT_TIMEOUT
= 60¶ Default timeout in seconds used for client session.
-
class
galaxy.http.
HttpClient
(limit=20, timeout=aiohttp.ClientTimeout, cookie_jar=None)¶ Bases:
object
Deprecated since version 0.41: Use http module functions instead
-
__init__
(limit=20, timeout=aiohttp.ClientTimeout, cookie_jar=None)¶
-
coroutine
close
()¶ Closes connection. Should be called in
shutdown()
-
coroutine
request
(method, url, *args, **kwargs)¶
-
-
galaxy.http.
create_tcp_connector
(*args, **kwargs)¶ Creates TCP connector with reasonable defaults. For details about available parameters refer to aiohttp.TCPConnector
- Return type
aiohttp.TCPConnector
-
galaxy.http.
create_client_session
(*args, **kwargs)¶ Creates client session with reasonable defaults. For details about available parameters refer to aiohttp.ClientSession
Exemplary customization:
from galaxy.http import create_client_session, create_tcp_connector session = create_client_session( headers={ "Keep-Alive": "true" }, connector=create_tcp_connector(limit=40), timeout=100)
- Return type
aiohttp.ClientSession