A high-performance HTTP/1.1 backend for the Kyoukai webserver using httptools.


KyoukaiProtocol(component, …) The base protocol for Kyoukai using httptools for a HTTP/1.0 or HTTP/1.1 interface.
class kyoukai.backends.httptools_.KyoukaiProtocol(component, parent_context: asphalt.core.context.Context, server_ip: str, server_port: int)[source]

Bases: asyncio.protocols.Protocol

The base protocol for Kyoukai using httptools for a HTTP/1.0 or HTTP/1.1 interface.

  • component – The kyoukai.asphalt.KyoukaiComponent associated with this request.
  • parent_context (Context) – The parent context for this request. A new HTTPRequestContext will be derived from this.
replace(other, *args, **kwargs)[source]

Replaces our type with the other.

Return type:type

Called when a message begins.

on_header(name, value)[source]

Called when a header has been received.

  • name (bytes) – The name of the header.
  • value (bytes) – The value of the header.

Called when the headers have been completely sent.


Called when part of the body has been received.

Parameters:body (bytes) – The body text.

Called when a URL is received from the client.


Called when a message is complete. This creates the worker task which will begin processing the request.


Called when a connection is made via asyncio.

Parameters:transport (WriteTransport) – The transport this is using.

Called when data is received into the connection.


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.
coroutine _wait()[source]

The main core of the protocol.

This constructs a new Werkzeug request from the headers.

write_response(response, fake_environ)[source]

Writes a Werkzeug response to the transport.


Writes data to the socket.


Writes data to the transport.


Does a raw write to the underlying transport, if we can.

Parameters:data (bytes) – The data to write.

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.


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).


Called when the transport’s buffer drains below the low-water mark.

See pause_writing() for details.