kyoukai.backends.httptools_

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

Classes

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.

Parameters:
  • 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
on_message_begin()[source]

Called when a message begins.

on_header(name, value)[source]

Called when a header has been received.

Parameters:
  • name (bytes) – The name of the header.
  • value (bytes) – The value of the header.
on_headers_complete()[source]

Called when the headers have been completely sent.

on_body(body)[source]

Called when part of the body has been received.

Parameters:body (bytes) – The body text.
on_url(url)[source]

Called when a URL is received from the client.

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.
data_received(data)[source]

Called when data is received into the connection.

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

write(data)[source]

Writes data to the socket.

raw_write(data)[source]

Writes data to the transport.

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