Extensions¶
Per-Message Deflate¶
websockets.extensions.permessage_deflate
implements the Compression
Extensions for WebSocket as specified in RFC 7692.
- class websockets.extensions.permessage_deflate.ClientPerMessageDeflateFactory(server_no_context_takeover: bool = False, client_no_context_takeover: bool = False, server_max_window_bits: Optional[int] = None, client_max_window_bits: Optional[Union[int, bool]] = None, compress_settings: Optional[Dict[str, Any]] = None)[source]¶
Client-side extension factory for the Per-Message Deflate extension.
Parameters behave as described in section 7.1 of RFC 7692. Set them to
True
to include them in the negotiation offer without a value or to an integer value to include them with this value.- Parameters:
server_no_context_takeover – defaults to
False
client_no_context_takeover – defaults to
False
server_max_window_bits – optional, defaults to
None
client_max_window_bits – optional, defaults to
None
compress_settings – optional, keyword arguments for
zlib.compressobj()
, excludingwbits
- class websockets.extensions.permessage_deflate.ServerPerMessageDeflateFactory(server_no_context_takeover: bool = False, client_no_context_takeover: bool = False, server_max_window_bits: Optional[int] = None, client_max_window_bits: Optional[int] = None, compress_settings: Optional[Dict[str, Any]] = None)[source]¶
Server-side extension factory for the Per-Message Deflate extension.
Parameters behave as described in section 7.1 of RFC 7692. Set them to
True
to include them in the negotiation offer without a value or to an integer value to include them with this value.- Parameters:
server_no_context_takeover – defaults to
False
client_no_context_takeover – defaults to
False
server_max_window_bits – optional, defaults to
None
client_max_window_bits – optional, defaults to
None
compress_settings – optional, keyword arguments for
zlib.compressobj()
, excludingwbits
Abstract classes¶
- class websockets.extensions.Extension[source]¶
Abstract class for extensions.
- decode(frame: websockets.frames.Frame, *, max_size: Optional[int] = None) websockets.frames.Frame [source]¶
Decode an incoming frame.
- Parameters:
frame – incoming frame
max_size – maximum payload size in bytes
- encode(frame: websockets.frames.Frame) websockets.frames.Frame [source]¶
Encode an outgoing frame.
- Parameters:
frame – outgoing frame
- property name: websockets.typing.ExtensionName¶
Extension identifier.
- class websockets.extensions.ClientExtensionFactory[source]¶
Abstract class for client-side extension factories.
- get_request_params() List[Tuple[str, Optional[str]]] [source]¶
Build request parameters.
Return a list of
(name, value)
pairs.
- property name: websockets.typing.ExtensionName¶
Extension identifier.
- process_response_params(params: Sequence[Tuple[str, Optional[str]]], accepted_extensions: Sequence[websockets.extensions.base.Extension]) websockets.extensions.base.Extension [source]¶
Process response parameters received from the server.
- Parameters:
params – list of
(name, value)
pairs.accepted_extensions – list of previously accepted extensions.
- Raises:
NegotiationError – if parameters aren’t acceptable
- class websockets.extensions.ServerExtensionFactory[source]¶
Abstract class for server-side extension factories.
- property name: websockets.typing.ExtensionName¶
Extension identifier.
- process_request_params(params: Sequence[Tuple[str, Optional[str]]], accepted_extensions: Sequence[websockets.extensions.base.Extension]) Tuple[List[Tuple[str, Optional[str]]], websockets.extensions.base.Extension] [source]¶
Process request parameters received from the client.
To accept the offer, return a 2-uple containing:
response parameters: a list of
(name, value)
pairsan extension: an instance of a subclass of
Extension
- Parameters:
params – list of
(name, value)
pairs.accepted_extensions – list of previously accepted extensions.
- Raises:
NegotiationError – to reject the offer, if parameters aren’t acceptable