A high-performance HTTP/1.1 backend for the Kyoukai webserver using httptools.
Functions
get_formatted_response(response, environment) |
Transform a Werkzeug response into a HTTP response that can be sent back down the wire. |
to_wsgi_environment(headers, method, path, ...) |
Produces a new WSGI environment from a set of data that is passed in. |
Classes
BytesIO |
Buffered I/O implementation using an in-memory bytes buffer. |
Context([parent, default_timeout]) |
Contexts give request handlers and callbacks access to resources. |
H2KyoukaiProtocol(component, parent_context) |
The base protocol for Kyoukai, using H2. |
KyoukaiProtocol(component, parent_context, ...) |
The base protocol for Kyoukai using httptools for a HTTP/1.0 or HTTP/1.1 interface. |
Request(environ[, populate_request, shallow]) |
Full featured request object implementing the following mixins: |
Response([response, status, headers, ...]) |
Full featured response object implementing the following mixins: |
Exceptions
BadRequest([description, response]) |
400 Bad Request |
InternalServerError([description, response]) |
500 Internal Server Error |
MethodNotAllowed([valid_methods, description]) |
405 Method Not Allowed |
kyoukai.backends.httptools_.KyoukaiProtocol(component, parent_context, server_ip, server_port)[source]¶Bases: asyncio.protocols.Protocol
The base protocol for Kyoukai using httptools for a HTTP/1.0 or HTTP/1.1 interface.
| Parameters: |
|
|---|
on_body(body)[source]¶Called when part of the body has been received.
| Parameters: | body (bytes) – The body text. |
|---|
on_message_complete()[source]¶Called when a message is complete. This creates the worker task which will begin processing the request.
connection_made(transport)[source]¶Called when a connection is made via asyncio.
| Parameters: | transport (WriteTransport) – The transport this is using. |
|---|
handle_parser_exception(exc)[source]¶Handles an exception when parsing.
This will not call into the app (hence why it is a normal function, and not a coroutine). It will also close the connection when it’s done.
| Parameters: | exc (Exception) – The exception to handle. |
|---|
_wait(self)[source]¶The main core of the protocol.
This constructs a new Werkzeug request from the headers.
_raw_write(data)[source]¶Does a raw write to the underlying transport, if we can.
| Parameters: | data (bytes) – The data to write. |
|---|
eof_received()¶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.
pause_writing()¶Called when the transport’s buffer goes over the high-water mark.
Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.
Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.
NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).
resume_writing()¶Called when the transport’s buffer drains below the low-water mark.
See pause_writing() for details.