decode_body

kafkit.registry.sansio.decode_body(content_type: Optional[str], body: bytes) Any

Decode an HTTP body based on the specified content type.

Parameters:
  • content_type (str or None) – Content type string, from the response header.

  • body (bytes) – Bytes content of the body.

Returns:

decoded – The decoded message.

  • If the content type is recognized as JSON, the result will be an object parsed from the JSON message.

  • If the content type isn’t recognized, the body is decoded into a string.

  • If the message is empty or content_type is None, the returned value is None.

Return type:

dict