alexapy.aiohttp.web_protocol
¶
Classes¶
RequestHandler
: HTTP protocol implementation.
- class alexapy.aiohttp.web_protocol.RequestHandler(manager: Server, *, loop: asyncio.events.AbstractEventLoop, keepalive_timeout: float = 75.0, tcp_keepalive: bool = True, logger: logging.Logger = <Logger aiohttp.server (WARNING)>, access_log_class: typing.Type[alexapy.aiohttp.abc.AbstractAccessLogger] = <class 'alexapy.aiohttp.web_log.AccessLogger'>, access_log: logging.Logger = <Logger aiohttp.access (WARNING)>, access_log_format: str = '%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"', debug: bool = False, max_line_size: int = 8190, max_headers: int = 32768, max_field_size: int = 8190, lingering_time: float = 10.0, read_bufsize: int = 65536, auto_decompress: bool = True)¶
HTTP protocol implementation.
RequestHandler handles incoming HTTP request. It reads request line, request headers and request payload and calls handle_request() method. By default it always returns with 404 response.
RequestHandler handles errors in incoming request, like bad status line, bad headers or incomplete payload. If any error occurs, connection gets closed.
- keepalive_timeout – number of seconds before closing
keep-alive connection
tcp_keepalive – TCP keep-alive is on, default is on
debug – enable debug mode
logger – custom logger object
access_log_class – custom class for access_logger
access_log – custom logging object
access_log_format – access log format string
loop – Optional event loop
max_line_size – Optional maximum header line size
max_field_size – Optional maximum header field size
max_headers – Optional maximum header size
Inheritance
- close() None ¶
Close connection.
Stop accepting new pipelining messages and close connection when handlers done processing messages.
- connection_lost(exc: Optional[BaseException]) None ¶
Called when the connection is lost or closed.
The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).
- connection_made(transport: asyncio.transports.BaseTransport) None ¶
Called when a connection is made.
The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.
- data_received(data: bytes) None ¶
Called when some data is received.
The argument is a bytes object.
- eof_received() None ¶
Called when the other end calls write_eof() or equivalent.
If this returns a false value (including None), the transport will close itself. If it returns a true value, closing the transport is up to the protocol.
- async finish_response(request: alexapy.aiohttp.web_request.BaseRequest, resp: alexapy.aiohttp.web_response.StreamResponse, start_time: float) bool ¶
Prepare the response and write_eof, then log access.
This has to be called within the context of any exception so the access logger can get exception information. Returns True if the client disconnects prematurely.
- force_close() None ¶
Forcefully close connection.
- handle_error(request: alexapy.aiohttp.web_request.BaseRequest, status: int = 500, exc: Optional[BaseException] = None, message: Optional[str] = None) alexapy.aiohttp.web_response.StreamResponse ¶
Handle errors.
Returns HTTP response with specific status code. Logs additional information. It always closes current connection.
- keep_alive(val: bool) None ¶
Set keep-alive connection mode.
- Parameters
val (bool) – new state.
- async shutdown(timeout: Optional[float] = 15.0) None ¶
Do worker process exit preparations.
We need to clean up everything and stop accepting requests. It is especially important for keep-alive connections.
- async start() None ¶
Process incoming request.
It reads request line, request headers and request payload, then calls handle_request() method. Subclass has to override handle_request(). start() handles various exceptions in request or response handling. Connection is being closed always unless keep_alive(True) specified.
Exceptions¶
RequestPayloadError
: Payload parsing error.PayloadAccessError
: Payload was accessed after response was sent.
- exception alexapy.aiohttp.web_protocol.RequestPayloadError¶
Payload parsing error.
Inheritance
- exception alexapy.aiohttp.web_protocol.PayloadAccessError¶
Payload was accessed after response was sent.
Inheritance