ContentSniffer

class ContentSniffer(**properties: Any)

Superclasses: Object

Implemented Interfaces: SessionFeature

Sniffs the mime type of messages.

A ContentSniffer tries to detect the actual content type of the files that are being downloaded by looking at some of the data before the Message emits its got_headers signal. ContentSniffer implements SessionFeature, so you can add content sniffing to a session with add_feature or add_feature_by_type.

Constructors

class ContentSniffer
classmethod new() ContentSniffer

Creates a new ContentSniffer.

Methods

class ContentSniffer
sniff(msg: Message, buffer: Bytes) tuple[str, dict[str, str]]

Sniffs buffer to determine its Content-Type.

The result may also be influenced by the Content-Type declared in msg’s response headers.

Parameters:
  • msg – the message to sniff

  • buffer – a buffer containing the start of msg’s response body