view.core.body

The implementation of request and response bodies.

Classes

BodyMixin(receive_data)

Mixin dataclass for common HTTP body operations.

Exceptions

BodyAlreadyUsedError(receive_data)

The body was already used on this response.

InvalidJSONError(*msg)

The body is not valid JSON data or something went wrong when parsing it.

exception BodyAlreadyUsedError(receive_data: AsyncIterator[bytes])

Bases: ViewError

The body was already used on this response.

Generally, this means that the same response object was executed multiple times.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class BodyMixin(receive_data: AsyncIterator[bytes])

Bases: object

Mixin dataclass for common HTTP body operations.

async body() bytes

Read the full body from the stream.

consumed: bool
async json(*, parse_function: ~collections.abc.Callable[[str], dict[str, ~typing.Any]] = <function loads>) dict[str, Any]

Read the body as JSON data.

receive_data: AsyncIterator[bytes]
async stream_body() AsyncIterator[bytes]

Incrementally stream the body without keeping the whole thing in-memory at a given time.

exception InvalidJSONError(*msg: str)

Bases: ViewError

The body is not valid JSON data or something went wrong when parsing it.

If this occurred when parsing the body for a request, the fix is usually to reraise this with an error 400 (Bad Request).

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.