Skip to content

blackbull.native

blackbull.native

Native send messages.

Presence is is not None, never truthiness: an empty body is real content. Preserve absent header/body/trailers through middleware. Introduce ASGI event dictionaries only at conversion boundaries.

NativeResponse

A response on the native send path: header and/or body and/or trailers.

header and trailers keep the response-field contract from creation on: names are lowercase tchar and values carry no CTL and no edge SP/HTAB (trimmed on entry). A field that cannot meet it raises ValueError/TypeError here; readers do not check again. header is None when absent (never []). body is None when absent; b'' is a real empty body. more_body marks a non-terminal body chunk. push makes this a promised request instead: its path is push and header holds request headers, with no response-only fields and no host (the authority is the parent's). more_trailers marks a non-terminal trailer event. expects_trailers (ASGI trailers: True) makes the sender withhold the terminal chunk until the trailers event.

body property writable

The body arm, or None when there is none. b'' is a real body.

content_length property

Octets in the body arm; 0 when there is no body.

content_type property

The content-type header value, or b'' if unset or headerless.

header property writable

The header arm as a mutable view, or None when there is none.

is_empty property

True when the body arm is absent or zero-length.

Distinct from body is None, which separates the two.

trailers property writable

The trailer arm as a mutable view, or None when there is none.

complete(status, header, body) classmethod

Header plus terminal body — a whole response in one object.

to_asgi()

Convert to the ASGI event list (http.response.* dicts).

One object → one or more ASGI events, in wire order. Used only at conversion boundaries — the external ASGI edge (external hosts / asgi=True) and the middleware native-read arms (cache, compression); the native H1 sender path never materialises these dicts.

with_trailers(status, header, body, trailers) classmethod

Header, body and trailers together — the gRPC unary shape.

more_body is True by construction, and load-bearing: HTTP2Sender only takes its trailers-coalescing path for a non-terminal body chunk, holding HEADERS + DATA so they flush with the trailing HEADERS in one write. END_STREAM rides the trailers either way (RFC 9113 §8.1).

NativeWSMessage

A native WebSocket send message.

ACCEPT carries subprotocol/headers; SEND exactly one of text/data; CLOSE code/reason. to_asgi maps data to the ASGI bytes key at a boundary.

to_asgi()

Convert to the ASGI websocket.* event list.

Used only at conversion boundaries — the external ASGI edge and the raw (conn, receive, send) compat surface — exactly like NativeResponse.to_asgi on the HTTP side.

asgi_send_boundary(inner_send)

Expand native HTTP/WebSocket messages to ASGI dictionaries at a boundary.

Use for external hosts and scope-declared middleware. Pass already-ASGI values through unchanged.