communication.httphandlers module

This module contains classes for the HTTP server and the HTTP client

class communication.httphandlers.HTTPClient(pool, addr, port, ssl_ctx)[source]

Bases: object

Class that serves as an HTTP Client

__init__(pool, addr, port, ssl_ctx)[source]

Initalizes an HTTP client instance

Parameters:
  • pool (Pool) – the communication pool to use

  • addr (str) – the address of the client

  • port (int) – the port of the client

  • ssl_ctx (Optional[SSLContext]) – an optional ssl context

Raises:

AttributeError – raised when the provided pool has no assigned http server.

recv(msg_id=None)[source]

Request a message from this client

Parameters:

msg_id (Union[str, int, None]) – an optional identifier of the message to receive

Return type:

Future[Dict[str, Any]]

Returns:

the received message

async send(message, msg_id=None, retry_delay=1)[source]

Sends a POST JSON request to containing the message to this client. If sending of message fails and retry_delay > 0 then retry after retry_delay seconds

Parameters:
  • message (Any) – the message to send

  • msg_id (Union[str, int, None]) – an optional identifier of the message to send

  • retry_delay (int) – number of seconds to wait before retrying after failure

Return type:

None

async shutdown()[source]

Shutdown HTTP Client. Closes open HTTP session.

Return type:

None

class communication.httphandlers.HTTPServer(pool, port, addr='0.0.0.0', ssl_ctx=None, get_handler=None, post_handler=None)[source]

Bases: object

Class for serving an HTTP server

__init__(pool, port, addr='0.0.0.0', ssl_ctx=None, get_handler=None, post_handler=None)[source]

Initalizes an HTTP server instance

Parameters:
  • pool (Pool) – the communication pool to use

  • port (int) – the port to bind to

  • addr (str) – the address to bind to

  • ssl_ctx (Optional[SSLContext]) – an optional ssl context

  • get_handler (Optional[Callable[[Request], Awaitable[StreamResponse]]]) – an optional GET handler to use

  • post_handler (Optional[Callable[[Request], Awaitable[StreamResponse]]]) – an optional POST handler to use

async run_server(get_handler=None, post_handler=None)[source]

Initializes the HTTP server.

Parameters:
  • get_handler (Optional[Callable[[Request], Awaitable[StreamResponse]]]) – a custom GET handler to handle GET requests

  • post_handler (Optional[Callable[[Request], Awaitable[StreamResponse]]]) – a custom POST handler to handle POST requests

Return type:

None

async shutdown()[source]

Shutdown HTTP Server.

Return type:

None