extensions.rst (1112B)
1 Write an extension 2 ================== 3 4 .. currentmodule:: websockets.extensions 5 6 During the opening handshake, WebSocket clients and servers negotiate which 7 extensions_ will be used with which parameters. Then each frame is processed 8 by extensions before being sent or after being received. 9 10 .. _extensions: https://www.rfc-editor.org/rfc/rfc6455.html#section-9 11 12 As a consequence, writing an extension requires implementing several classes: 13 14 * Extension Factory: it negotiates parameters and instantiates the extension. 15 16 Clients and servers require separate extension factories with distinct APIs. 17 18 Extension factories are the public API of an extension. 19 20 * Extension: it decodes incoming frames and encodes outgoing frames. 21 22 If the extension is symmetrical, clients and servers can use the same 23 class. 24 25 Extensions are initialized by extension factories, so they don't need to be 26 part of the public API of an extension. 27 28 websockets provides base classes for extension factories and extensions. 29 See :class:`ClientExtensionFactory`, :class:`ServerExtensionFactory`, 30 and :class:`Extension` for details.