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 useaddr (
str
) – the address of the clientport (
int
) – the port of the clientssl_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 sendmsg_id (
Union
[str
,int
,None
]) – an optional identifier of the message to sendretry_delay (
int
) – number of seconds to wait before retrying after failure
- 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 useport (
int
) – the port to bind toaddr (
str
) – the address to bind tossl_ctx (
Optional
[SSLContext
]) – an optional ssl contextget_handler (
Optional
[Callable
[[Request
],Awaitable
[StreamResponse
]]]) – an optional GET handler to usepost_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 requestspost_handler (
Optional
[Callable
[[Request
],Awaitable
[StreamResponse
]]]) – a custom POST handler to handle POST requests
- Return type:
None