summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/docs/howto/extensions.rst
blob: 3c8a7d72a64a8f11b95279caeeafd598150a0b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Write an extension
==================

.. currentmodule:: websockets.extensions

During the opening handshake, WebSocket clients and servers negotiate which
extensions_ will be used with which parameters. Then each frame is processed
by extensions before being sent or after being received.

.. _extensions: https://www.rfc-editor.org/rfc/rfc6455.html#section-9

As a consequence, writing an extension requires implementing several classes:

* Extension Factory: it negotiates parameters and instantiates the extension.

  Clients and servers require separate extension factories with distinct APIs.

  Extension factories are the public API of an extension.

* Extension: it decodes incoming frames and encodes outgoing frames.

  If the extension is symmetrical, clients and servers can use the same
  class.

  Extensions are initialized by extension factories, so they don't need to be
  part of the public API of an extension.

websockets provides base classes for extension factories and extensions.
See :class:`ClientExtensionFactory`, :class:`ServerExtensionFactory`,
and :class:`Extension` for details.