Debian Codegraph @

docs/project/changelog.rst

raw
1 Changelog
2 =========
3
4 .. currentmodule:: websockets
5
6 .. _backwards-compatibility policy:
7
8 Backwards-compatibility policy
9 ------------------------------
10
11 websockets is intended for production use. Therefore, stability is a goal.
12
13 websockets also aims at providing the best API for WebSocket in Python.
14
15 While we value stability, we value progress more. When an improvement requires
16 changing a public API, we make the change and document it in this changelog.
17
18 When possible with reasonable effort, we preserve backwards-compatibility for
19 five years after the release that introduced the change.
20
21 When a release contains backwards-incompatible API changes, the major version
22 is increased, else the minor version is increased. Patch versions are only for
23 fixing regressions shortly after a release.
24
25 Only documented APIs are public. Undocumented, private APIs may change without
26 notice.
27
28 .. _17.1:
29
30 17.1
31 ----
32
33 *August 26, 2026*
34
35 New features
36 ............
37
38 * Added support for reconnecting automatically by using
39 :func:`~sync.client.reconnect` as an iterator to the :mod:`threading`
40 implementation.
41
42 * :func:`~sync.client.connect` now follows redirects in the :mod:`threading`
43 implementation.
44
45 * :func:`~sync.client.connect` can connect to another host and port than those
46 specified in the URI in the :mod:`threading` implementation.
47
48 Improvements
49 ............
50
51 * Connections are now garbage collected immediately once closed.
52
53 * :func:`~sync.client.unix_connect` and :func:`~sync.server.unix_serve` now accept
54 path-like objects, such as :class:`pathlib.Path`, in the ``path`` argument.
55
56 .. _17.0.1:
57
58 17.0.1
59 ------
60
61 *July 31, 2026*
62
63 Bug fixes
64 .........
65
66 * Restored compatibility of :meth:`~asyncio.server.Server.serve_forever` in the
67 :mod:`asyncio` implementation with third-party event loops such as uvloop_.
68
69 * Prevented the Trio implementation from crashing when backpressure kicks in,
70 i.e. when receiving data faster than the application can process it.
71
72 .. _uvloop: https://uvloop.readthedocs.io/
73
74 .. _17.0:
75
76 17.0
77 ----
78
79 *July 29, 2026*
80
81 Backwards-incompatible changes
82 ..............................
83
84 .. admonition:: websockets 17.0 requires Python ≥ 3.11.
85 :class: tip
86
87 websockets 16.1 is the last version supporting Python 3.10.
88
89 .. admonition:: Aliases for modules moved or deprecated in 9.0 are removed.
90 :class: tip
91
92 See the changelog of version 9.0 for details.
93
94 .. admonition:: ``process_request`` may receive requests using an HTTP method
95 other than ``GET`` or using the HTTP/1.0 protocol.
96 :class: caution
97
98 Previously, the server closed the connection without returning an HTTP
99 response. Now, ``process_request`` runs and can return an HTTP response.
100
101 .. admonition:: Several boolean arguments are now keyword-only.
102 :class: note
103
104 If you were passing some of the following as positional arguments, you must
105 update your code to pass them as keyword arguments.
106
107 * ``send(text=...)``
108 * ``ping(ack_on_close=...)``
109 * ``broadcast(raise_exceptions=...)``
110
111 .. admonition:: Encoding and decoding non-ASCII headers in handshake requests
112 and responses changed.
113 :class: note
114
115 The previous behavior was undocumented, inconsistent, and didn't match the
116 HTTP specification. If you relied on the encoding being UTF-8 or ASCII with
117 surrogate escapes, depending on the context, you must switch to ISO-8859-1.
118
119 .. admonition:: In the :mod:`threading` implementation, the ``socket`` argument
120 is renamed to ``sock``.
121 :class: note
122
123 The first argument of :class:`~sync.client.ClientConnection` and
124 :class:`~sync.server.ServerConnection` is renamed from ``socket`` to
125 ``sock`` for consistency with :func:`~sync.client.connect` and
126 :func:`~sync.server.serve`. The first argument of
127 :class:`~sync.server.Server` is also renamed. If you're passing it as a
128 keyword argument, you must change your code.
129
130 New features
131 ............
132
133 .. admonition:: websockets 17.0 introduces a :mod:`trio` implementation.
134 :class: important
135
136 It is an alternative to the :mod:`asyncio` implementation.
137
138 See :func:`websockets.trio.client.connect` and
139 :func:`websockets.trio.server.serve` for details.
140
141 * Validated compatibility with Python 3.15.
142
143 * Added :func:`~sync.server.broadcast` to the :mod:`threading` implementation.
144
145 * Made the set of active connections available in the :attr:`Server.connections
146 <sync.server.Server.connections>` property in the :mod:`threading`
147 implementation.
148
149 * Closed connections when shutting down the server in the :mod:`threading`
150 implementation. See :meth:`~sync.server.Server.shutdown` for details.
151
152 * Added the ``--insecure`` option to the ``websockets`` CLI to disable TLS
153 certificate validation.
154
155 Improvements
156 ............
157
158 * Supported non-ASCII headers consistently in handshake requests and responses,
159 using ISO-8859-1 encoding.
160
161 * Replied with HTTP 405 Method Not Allowed when the handshake request doesn't
162 use the GET method, and with HTTP 505 HTTP Version Not Supported when it
163 doesn't use HTTP/1.1, instead of closing the connection.
164
165 * Replied with HTTP 414 URI Too Long or 431 Request Header Fields Too Large
166 when the handshake request exceeds a security limit, instead of closing
167 the connection.
168
169 * Reduced noise in server logs when clients fail to establish a connection.
170
171 * Clarified logs when ``process_request`` sends a plain HTTP response, without
172 attempting to open a WebSocket connection.
173
174 * Added the ``reconnect_delays`` argument for customizing the delays between
175 reconnection attempts in :func:`~asyncio.client.connect`, beyond existing
176 ``WEBSOCKETS_BACKOFF_*`` environment variables.
177
178 * Added wheels for Windows ARM64 and Linux i686.
179
180 Bug fixes
181 .........
182
183 * Restored compatibility of the ``websockets`` CLI with Windows.
184
185 * Fixed :meth:`~asyncio.server.Server.serve_forever` in the :mod:`asyncio`
186 implementation so that canceling it always closes connections gracefully.
187
188 * Fixed a bug that could delay or block the client in the :mod:`threading`
189 implementation on macOS when the opening handshake fails.
190
191 .. _16.1.1:
192
193 16.1.1
194 ------
195
196 *July 18, 2026*
197
198 Bug fixes
199 .........
200
201 * Reverted a backwards-incompatible change in decoding non-ASCII header values.
202
203 .. _16.1:
204
205 16.1
206 ----
207
208 *July 9, 2026*
209
210 New features
211 ............
212
213 * Added an option to force :func:`~asyncio.server.broadcast` to send
214 :class:`bytes` in text frames, or :class:`str` in binary frames.
215
216 Improvements
217 ............
218
219 * Stripped ``Authorization``, ``Cookie``, and ``Proxy-Authorization`` headers
220 when clients follow cross-origin redirects, a security hardening measure.
221
222 * Escaped control characters in incoming messages in the ``websockets`` CLI.
223
224 * Prevented setting invalid header values in :class:`~datastructures.Headers`.
225
226 * Rejected incorrect fragmented, compressed messages.
227
228 * Added wheels for ARMv7, PowerPC, RISC-V, and S/390.
229
230 Bug fixes
231 .........
232
233 * Prevented ``str(frame)`` from crashing when a text frame is fragmented in the
234 middle of a UTF-8 sequence.
235
236 .. _16.0:
237
238 16.0
239 ----
240
241 *January 10, 2026*
242
243 Backwards-incompatible changes
244 ..............................
245
246 .. admonition:: websockets 16.0 requires Python ≥ 3.10.
247 :class: tip
248
249 websockets 15.0 is the last version supporting Python 3.9.
250
251 New features
252 ............
253
254 * Validated compatibility with Python 3.14.
255
256 * Added support for free-threaded Python.
257
258 Improvements
259 ............
260
261 * Allowed setting separate limits for messages and fragments with ``max_size``.
262
263 * Added support for HTTP/1.0 proxies.
264
265 * Added support for customizing the close code and reason for connections in
266 :meth:`Server.close <asyncio.server.Server.close>`.
267
268 Bug fixes
269 .........
270
271 * Prevented :meth:`~asyncio.connection.Connection.recv` from returning
272 :class:`bytearray` instead of :class:`bytes` in edge cases.
273
274 * Fixed a race condition that could lead to an exception when closing
275 connections in the :mod:`threading` implementation.
276
277 15.0.1
278 ------
279
280 *March 5, 2025*
281
282 Improvements
283 ............
284
285 * Added an entry point for running the CLI as ``websockets``.
286
287 Bug fixes
288 .........
289
290 * Prevented an exception when exiting the CLI.
291
292 .. _15.0:
293
294 15.0
295 ----
296
297 *February 16, 2025*
298
299 Backwards-incompatible changes
300 ..............................
301
302 .. admonition:: Client connections use SOCKS and HTTP proxies automatically.
303 :class: important
304
305 If a proxy is configured in the operating system or with an environment
306 variable, websockets uses it automatically when connecting to a server.
307 SOCKS proxies require installing the third-party library `python-socks`_.
308
309 If you want to disable the proxy, add ``proxy=None`` when calling
310 :func:`~asyncio.client.connect`.
311
312 See :doc:`proxies <../topics/proxies>` for details.
313
314 .. _python-socks: https://github.com/romis2012/python-socks
315
316 .. admonition:: Keepalive is enabled in the :mod:`threading` implementation.
317 :class: important
318
319 The :mod:`threading` implementation now sends Ping frames at regular
320 intervals and closes the connection if it doesn't receive a matching Pong
321 frame just like the :mod:`asyncio` implementation.
322
323 See :doc:`keepalive and latency <../topics/keepalive>` for details.
324
325 New features
326 ............
327
328 * Added :func:`~asyncio.router.route` and :func:`~asyncio.router.unix_route` to
329 dispatch connections to handlers based on the request path. Read more about
330 routing in :doc:`routing <../topics/routing>`.
331
332 Improvements
333 ............
334
335 * Refreshed several how-to guides and topic guides.
336
337 * Added type overloads for the ``decode`` argument of
338 :meth:`~asyncio.connection.Connection.recv`. This may simplify static typing.
339
340 .. _14.2:
341
342 14.2
343 ----
344
345 *January 19, 2025*
346
347 New features
348 ............
349
350 * Added support for regular expressions in the ``origins`` argument of
351 :func:`~asyncio.server.serve`.
352
353 Bug fixes
354 .........
355
356 * Wrapped errors when reading the opening handshake request or response in
357 :exc:`~exceptions.InvalidMessage` so that :func:`~asyncio.client.connect`
358 raises :exc:`~exceptions.InvalidHandshake` or a subclass when the opening
359 handshake fails.
360
361 * Fixed :meth:`~sync.connection.Connection.recv` with ``timeout=0`` in the
362 :mod:`threading` implementation. If a message is already received, it is
363 returned. Previously, :exc:`TimeoutError` was raised incorrectly.
364
365 * Fixed a crash in the :mod:`asyncio` implementation when canceling a ping
366 then receiving the corresponding pong.
367
368 * Prevented :meth:`~asyncio.connection.Connection.close` from blocking when
369 the network becomes unavailable or when receive buffers are saturated in
370 the :mod:`asyncio` and :mod:`threading` implementations.
371
372 .. _14.1:
373
374 14.1
375 ----
376
377 *November 13, 2024*
378
379 Improvements
380 ............
381
382 * Supported ``max_queue=None`` in the :mod:`asyncio` and :mod:`threading`
383 implementations for consistency with the legacy implementation, even though
384 this is never a good idea.
385
386 * Added ``close_code`` and ``close_reason`` attributes in the :mod:`asyncio` and
387 :mod:`threading` implementations for consistency with the legacy
388 implementation.
389
390 Bug fixes
391 .........
392
393 * Once the connection is closed, messages previously received and buffered can
394 be read in the :mod:`asyncio` and :mod:`threading` implementations, just like
395 in the legacy implementation.
396
397 .. _14.0:
398
399 14.0
400 ----
401
402 *November 9, 2024*
403
404 Backwards-incompatible changes
405 ..............................
406
407 .. admonition:: websockets 14.0 requires Python ≥ 3.9.
408 :class: tip
409
410 websockets 13.1 is the last version supporting Python 3.8.
411
412 .. admonition:: The new :mod:`asyncio` implementation is now the default.
413 :class: attention
414
415 The following aliases in the ``websockets`` package were switched to the new
416 :mod:`asyncio` implementation::
417
418 from websockets import connect, unix_connext
419 from websockets import broadcast, serve, unix_serve
420
421 If you're using any of them, then you must follow the :doc:`upgrade guide
422 <../howto/upgrade>` immediately.
423
424 Alternatively, you may stick to the legacy :mod:`asyncio` implementation for
425 now by importing it explicitly::
426
427 from websockets.legacy.client import connect, unix_connect
428 from websockets.legacy.server import broadcast, serve, unix_serve
429
430 .. admonition:: The legacy :mod:`asyncio` implementation is now deprecated.
431 :class: caution
432
433 The :doc:`upgrade guide <../howto/upgrade>` provides complete instructions
434 to migrate your application.
435
436 Aliases for deprecated API were removed from ``websockets.__all__``, meaning
437 that they cannot be imported with ``from websockets import *`` anymore.
438
439 .. admonition:: Several API raise :exc:`ValueError` instead of :exc:`TypeError`
440 on invalid arguments.
441 :class: note
442
443 :func:`~asyncio.client.connect`, :func:`~asyncio.client.unix_connect`, and
444 :func:`~asyncio.server.basic_auth` in the :mod:`asyncio` implementation as
445 well as :func:`~sync.client.connect`, :func:`~sync.client.unix_connect`,
446 :func:`~sync.server.serve`, :func:`~sync.server.unix_serve`, and
447 :func:`~sync.server.basic_auth` in the :mod:`threading` implementation now
448 raise :exc:`ValueError` when a required argument isn't provided or an
449 argument that is incompatible with others is provided.
450
451 .. admonition:: :attr:`Frame.data <frames.Frame.data>` is now a bytes-like object.
452 :class: note
453
454 In addition to :class:`bytes`, it may be a :class:`bytearray` or a
455 :class:`memoryview`. If you wrote an :class:`~extensions.Extension` that
456 relies on methods not provided by these types, you must update your code.
457
458 .. admonition:: The signature of :exc:`~exceptions.PayloadTooBig` changed.
459 :class: note
460
461 If you wrote an extension that raises :exc:`~exceptions.PayloadTooBig` in
462 :meth:`~extensions.Extension.decode`, for example, you must replace
463 ``PayloadTooBig(f"over size limit ({size} > {max_size} bytes)")`` with
464 ``PayloadTooBig(size, max_size)``.
465
466 New features
467 ............
468
469 * Added an option to receive text frames as :class:`bytes`, without decoding,
470 in the :mod:`threading` implementation; also binary frames as :class:`str`.
471
472 * Added an option to send :class:`bytes` in a text frame in the :mod:`asyncio`
473 and :mod:`threading` implementations; also :class:`str` in a binary frame.
474
475 Improvements
476 ............
477
478 * The :mod:`threading` implementation receives messages faster.
479
480 * Sending or receiving large compressed messages is now faster.
481
482 * Errors when a fragmented message is too large are clearer.
483
484 * Log messages at the :data:`~logging.WARNING` and :data:`~logging.INFO` levels
485 no longer include stack traces.
486
487 Bug fixes
488 .........
489
490 * Clients no longer crash when the server rejects the opening handshake and the
491 HTTP response doesn't Include a ``Content-Length`` header.
492
493 * Returning an HTTP response in ``process_request`` or ``process_response``
494 doesn't generate a log message at the :data:`~logging.ERROR` level anymore.
495
496 * Connections are closed with code 1007 (invalid data) when receiving invalid
497 UTF-8 in a text frame.
498
499 .. _13.1:
500
501 13.1
502 ----
503
504 *September 21, 2024*
505
506 Backwards-incompatible changes
507 ..............................
508
509 .. admonition:: The ``code`` and ``reason`` attributes of
510 :exc:`~exceptions.ConnectionClosed` are deprecated.
511 :class: note
512
513 They were removed from the documentation in version 10.0, due to their
514 spec-compliant but counter-intuitive behavior, but they were kept in
515 the code for backwards compatibility. They're now formally deprecated.
516
517 New features
518 ............
519
520 * Added support for reconnecting automatically by using
521 :func:`~asyncio.client.connect` as an asynchronous iterator to the new
522 :mod:`asyncio` implementation.
523
524 * :func:`~asyncio.client.connect` now follows redirects in the new
525 :mod:`asyncio` implementation.
526
527 * Added HTTP Basic Auth to the :mod:`asyncio` and :mod:`threading`
528 implementations of servers.
529
530 * Made the set of active connections available in the :attr:`Server.connections
531 <asyncio.server.Server.connections>` property.
532
533 Improvements
534 ............
535
536 * Improved reporting of errors during the opening handshake.
537
538 * Raised :exc:`~exceptions.ConcurrencyError` on unsupported concurrent calls.
539 Previously, :exc:`RuntimeError` was raised. For backwards compatibility,
540 :exc:`~exceptions.ConcurrencyError` is a subclass of :exc:`RuntimeError`.
541
542 Bug fixes
543 .........
544
545 * The :mod:`asyncio` and :mod:`threading` implementations of servers don't
546 start the connection handler anymore when ``process_request`` or
547 ``process_response`` returns an HTTP response.
548
549 * Fixed a bug in the :mod:`threading` implementation that could lead to
550 incorrect error reporting when closing a connection while
551 :meth:`~sync.connection.Connection.recv` is running.
552
553 13.0.1
554 ------
555
556 *August 28, 2024*
557
558 Bug fixes
559 .........
560
561 * Restored the C extension in the source distribution.
562
563 .. _13.0:
564
565 13.0
566 ----
567
568 *August 20, 2024*
569
570 Backwards-incompatible changes
571 ..............................
572
573 .. admonition:: Receiving the request path in the second parameter of connection
574 handlers is deprecated.
575 :class: note
576
577 If you implemented the connection handler of a server as::
578
579 async def handler(request, path):
580 ...
581
582 You should switch to the pattern recommended since version 10.1::
583
584 async def handler(request):
585 path = request.path # only if handler() uses the path argument
586 ...
587
588 .. admonition:: The ``ssl_context`` argument of :func:`~sync.client.connect`
589 and :func:`~sync.server.serve` in the :mod:`threading` implementation is
590 renamed to ``ssl``.
591 :class: note
592
593 This aligns the API of the :mod:`threading` implementation with the
594 :mod:`asyncio` implementation.
595
596 For backwards compatibility, ``ssl_context`` is still supported.
597
598 .. admonition:: The ``WebSocketServer`` class in the :mod:`threading`
599 implementation is renamed to :class:`~sync.server.Server`.
600 :class: note
601
602 This change should be transparent because this class shouldn't be
603 instantiated directly; :func:`~sync.server.serve` returns an instance.
604
605 Regardless, an alias provides backwards compatibility.
606
607 New features
608 ............
609
610 .. admonition:: websockets 13.0 introduces a new :mod:`asyncio` implementation.
611 :class: important
612
613 This new implementation is intended to be a drop-in replacement for the
614 current implementation. It will become the default in a future release.
615
616 Please try it and report any issue that you encounter! The :doc:`upgrade
617 guide <../howto/upgrade>` explains everything you need to know about the
618 upgrade process.
619
620 * Validated compatibility with Python 3.12 and 3.13.
621
622 * Added an option to receive text frames as :class:`bytes`, without decoding,
623 in the :mod:`asyncio` implementation; also binary frames as :class:`str`.
624
625 * Added :doc:`environment variables <../reference/variables>` to configure debug
626 logs, the ``Server`` and ``User-Agent`` headers, as well as security limits.
627
628 If you were monkey-patching constants, be aware that they were renamed, which
629 will break your configuration. You must switch to the environment variables.
630
631 Improvements
632 ............
633
634 * The error message in server logs when a header is too long is more explicit.
635
636 Bug fixes
637 .........
638
639 * Fixed a bug in the :mod:`threading` implementation that could prevent the
640 program from exiting when a connection wasn't closed properly.
641
642 * Redirecting from a ``ws://`` URI to a ``wss://`` URI now works.
643
644 * ``broadcast(raise_exceptions=True)`` no longer crashes when there isn't any
645 exception.
646
647 .. _12.0:
648
649 12.0
650 ----
651
652 *October 21, 2023*
653
654 Backwards-incompatible changes
655 ..............................
656
657 .. admonition:: websockets 12.0 requires Python ≥ 3.8.
658 :class: tip
659
660 websockets 11.0 is the last version supporting Python 3.7.
661
662 Improvements
663 ............
664
665 * Made convenience imports from ``websockets`` compatible with static code
666 analysis tools such as auto-completion in an IDE or type checking with mypy_.
667
668 .. _mypy: https://github.com/python/mypy
669
670 * Accepted a plain :class:`int` where an :class:`~http.HTTPStatus` is expected.
671
672 * Added :class:`~frames.CloseCode`.
673
674 11.0.3
675 ------
676
677 *May 7, 2023*
678
679 Bug fixes
680 .........
681
682 * Fixed the :mod:`threading` implementation of servers on Windows.
683
684 11.0.2
685 ------
686
687 *April 18, 2023*
688
689 Bug fixes
690 .........
691
692 * Fixed a deadlock in the :mod:`threading` implementation when closing a
693 connection without reading all messages.
694
695 11.0.1
696 ------
697
698 *April 6, 2023*
699
700 Bug fixes
701 .........
702
703 * Restored the C extension in the source distribution.
704
705 .. _11.0:
706
707 11.0
708 ----
709
710 *April 2, 2023*
711
712 Backwards-incompatible changes
713 ..............................
714
715 .. admonition:: The Sans-I/O implementation was moved.
716 :class: caution
717
718 Aliases provide compatibility for all previously public APIs according to
719 the `backwards-compatibility policy`_.
720
721 * The ``connection`` module was renamed to ``protocol``.
722
723 * The ``connection.Connection``, ``server.ServerConnection``, and
724 ``client.ClientConnection`` classes were renamed to ``protocol.Protocol``,
725 ``server.ServerProtocol``, and ``client.ClientProtocol``.
726
727 .. admonition:: Sans-I/O protocol constructors now use keyword-only arguments.
728 :class: caution
729
730 If you instantiate :class:`~server.ServerProtocol` or
731 :class:`~client.ClientProtocol` directly, make sure you are using keyword
732 arguments.
733
734 .. admonition:: Closing a connection without an empty close frame is OK.
735 :class: note
736
737 Receiving an empty close frame now results in
738 :exc:`~exceptions.ConnectionClosedOK` instead of
739 :exc:`~exceptions.ConnectionClosedError`.
740
741 As a consequence, calling ``WebSocket.close()`` without arguments in a
742 browser isn't reported as an error anymore.
743
744 .. admonition:: :func:`~legacy.server.serve` times out on the opening handshake
745 after 10 seconds by default.
746 :class: note
747
748 You can adjust the timeout with the ``open_timeout`` parameter. Set it to
749 :obj:`None` to disable the timeout entirely.
750
751 New features
752 ............
753
754 .. admonition:: websockets 11.0 introduces a :mod:`threading` implementation.
755 :class: important
756
757 It may be more convenient if you don't need to manage many connections and
758 you're more comfortable with :mod:`threading` than :mod:`asyncio`.
759
760 It is particularly suited to client applications that establish only one
761 connection. It may be used for servers handling few connections.
762
763 See :func:`websockets.sync.client.connect` and
764 :func:`websockets.sync.server.serve` for details.
765
766 * Added ``open_timeout`` to :func:`~legacy.server.serve`.
767
768 * Made it possible to close a server without closing existing connections.
769
770 * Added :attr:`~server.ServerProtocol.select_subprotocol` to customize
771 negotiation of subprotocols in the Sans-I/O layer.
772
773 Improvements
774 ............
775
776 * Added platform-independent wheels.
777
778 * Improved error handling in :func:`~legacy.server.broadcast`.
779
780 * Set ``server_hostname`` automatically on TLS connections when providing a
781 ``sock`` argument to :func:`~sync.client.connect`.
782
783 .. _10.4:
784
785 10.4
786 ----
787
788 *October 25, 2022*
789
790 New features
791 ............
792
793 * Validated compatibility with Python 3.11.
794
795 * Added the :attr:`~legacy.protocol.WebSocketCommonProtocol.latency` property to
796 protocols.
797
798 * Changed :attr:`~legacy.protocol.WebSocketCommonProtocol.ping` to return the
799 latency of the connection.
800
801 * Supported overriding or removing the ``User-Agent`` header in clients and the
802 ``Server`` header in servers.
803
804 * Added deployment guides for more Platform as a Service providers.
805
806 Improvements
807 ............
808
809 * Improved FAQ.
810
811 .. _10.3:
812
813 10.3
814 ----
815
816 *April 17, 2022*
817
818 Backwards-incompatible changes
819 ..............................
820
821 .. admonition:: The ``exception`` attribute of :class:`~http11.Request` and
822 :class:`~http11.Response` is deprecated.
823 :class: note
824
825 Use the ``handshake_exc`` attribute of :class:`~server.ServerProtocol` and
826 :class:`~client.ClientProtocol` instead.
827
828 See :doc:`../howto/sansio` for details.
829
830 Improvements
831 ............
832
833 * Reduced noise in logs when :mod:`ssl` or :mod:`zlib` raise exceptions.
834
835 .. _10.2:
836
837 10.2
838 ----
839
840 *February 21, 2022*
841
842 Improvements
843 ............
844
845 * Made compression negotiation more lax for compatibility with Firefox.
846
847 * Improved FAQ and quick start guide.
848
849 Bug fixes
850 .........
851
852 * Fixed backwards-incompatibility in 10.1 for connection handlers created with
853 :func:`functools.partial`.
854
855 * Avoided leaking open sockets when :func:`~legacy.client.connect` is canceled.
856
857 .. _10.1:
858
859 10.1
860 ----
861
862 *November 14, 2021*
863
864 New features
865 ............
866
867 * Added a tutorial.
868
869 * Made the second parameter of connection handlers optional. The request path is
870 available in the :attr:`~legacy.protocol.WebSocketCommonProtocol.path`
871 attribute of the first argument.
872
873 If you implemented the connection handler of a server as::
874
875 async def handler(request, path):
876 ...
877
878 You should replace it with::
879
880 async def handler(request):
881 path = request.path # only if handler() uses the path argument
882 ...
883
884 * Added ``python -m websockets --version``.
885
886 Improvements
887 ............
888
889 * Added wheels for Python 3.10, PyPy 3.7, and for more platforms.
890
891 * Reverted optimization of default compression settings for clients, mainly to
892 avoid triggering bugs in poorly implemented servers like `AWS API Gateway`_.
893
894 .. _AWS API Gateway: https://github.com/python-websockets/websockets/issues/1065
895
896 * Mirrored the entire :class:`~asyncio.Server` API in
897 :class:`~legacy.server.WebSocketServer`.
898
899 * Improved performance for large messages on ARM processors.
900
901 * Documented how to auto-reload on code changes in development.
902
903 Bug fixes
904 .........
905
906 * Avoided half-closing TCP connections that are already closed.
907
908 .. _10.0:
909
910 10.0
911 ----
912
913 *September 9, 2021*
914
915 Backwards-incompatible changes
916 ..............................
917
918 .. admonition:: websockets 10.0 requires Python ≥ 3.7.
919 :class: tip
920
921 websockets 9.1 is the last version supporting Python 3.6.
922
923 .. admonition:: The ``loop`` parameter is deprecated from all APIs.
924 :class: caution
925
926 This reflects a decision made in Python 3.8. See the release notes of
927 Python 3.10 for details.
928
929 The ``loop`` parameter is also removed
930 from :class:`~legacy.server.WebSocketServer`. This should be transparent.
931
932 .. admonition:: :func:`~legacy.client.connect` times out after 10 seconds by default.
933 :class: note
934
935 You can adjust the timeout with the ``open_timeout`` parameter. Set it to
936 :obj:`None` to disable the timeout entirely.
937
938 .. admonition:: The ``legacy_recv`` option is deprecated.
939 :class: note
940
941 See the release notes of websockets 3.0 for details.
942
943 .. admonition:: The signature of :exc:`~exceptions.ConnectionClosed` changed.
944 :class: note
945
946 If you raise :exc:`~exceptions.ConnectionClosed` or a subclass, rather
947 than catch them when websockets raises them, you must change your code.
948
949 .. admonition:: A ``msg`` parameter was added to :exc:`~exceptions.InvalidURI`.
950 :class: note
951
952 If you raise :exc:`~exceptions.InvalidURI`, rather than catch it when
953 websockets raises it, you must change your code.
954
955 New features
956 ............
957
958 .. admonition:: websockets 10.0 introduces a `Sans-I/O API
959 <https://sans-io.readthedocs.io/>`_ for easier integration
960 in third-party libraries.
961 :class: important
962
963 If you're integrating websockets in a library, rather than just using it,
964 look at the :doc:`Sans-I/O integration guide <../howto/sansio>`.
965
966 * Added compatibility with Python 3.10.
967
968 * Added :func:`~legacy.server.broadcast` to send a message to many clients.
969
970 * Added support for reconnecting automatically by using
971 :func:`~legacy.client.connect` as an asynchronous iterator.
972
973 * Added ``open_timeout`` to :func:`~legacy.client.connect`.
974
975 * Documented how to integrate with `Django <https://www.djangoproject.com/>`_.
976
977 * Documented how to deploy websockets in production, with several options.
978
979 * Documented how to authenticate connections.
980
981 * Documented how to broadcast messages to many connections.
982
983 Improvements
984 ............
985
986 * Improved logging. See the :doc:`logging guide <../topics/logging>`.
987
988 * Optimized default compression settings to reduce memory usage.
989
990 * Optimized processing of client-to-server messages when the C extension isn't
991 available.
992
993 * Supported relative redirects in :func:`~legacy.client.connect`.
994
995 * Handled TCP connection drops during the opening handshake.
996
997 * Made it easier to customize authentication with
998 :meth:`~legacy.auth.BasicAuthWebSocketServerProtocol.check_credentials`.
999
1000 * Provided additional information in :exc:`~exceptions.ConnectionClosed`
1001 exceptions.
1002
1003 * Clarified several exceptions or log messages.
1004
1005 * Restructured documentation.
1006
1007 * Improved API documentation.
1008
1009 * Extended FAQ.
1010
1011 Bug fixes
1012 .........
1013
1014 * Avoided a crash when receiving a ping while the connection is closing.
1015
1016 .. _9.1:
1017
1018 9.1
1019 ---
1020
1021 *May 27, 2021*
1022
1023 Security fix
1024 ............
1025
1026 .. admonition:: websockets 9.1 fixes a security issue introduced in 8.0.
1027 :class: danger
1028
1029 Version 8.0 was vulnerable to timing attacks on HTTP Basic Auth passwords
1030 (`CVE-2021-33880`_).
1031
1032 .. _CVE-2021-33880: https://nvd.nist.gov/vuln/detail/CVE-2021-33880
1033
1034 9.0.2
1035 -----
1036
1037 *May 15, 2021*
1038
1039 Bug fixes
1040 .........
1041
1042 * Restored compatibility of ``python -m websockets`` with Python < 3.9.
1043
1044 * Restored compatibility with mypy.
1045
1046 9.0.1
1047 -----
1048
1049 *May 2, 2021*
1050
1051 Bug fixes
1052 .........
1053
1054 * Fixed issues with the packaging of the 9.0 release.
1055
1056 .. _9.0:
1057
1058 9.0
1059 ---
1060
1061 *May 1, 2021*
1062
1063 Backwards-incompatible changes
1064 ..............................
1065
1066 .. admonition:: Several modules are moved or deprecated.
1067 :class: caution
1068
1069 Aliases provide compatibility for all previously public APIs according to
1070 the `backwards-compatibility policy`_
1071
1072 * :class:`~datastructures.Headers` and
1073 :exc:`~datastructures.MultipleValuesError` are moved from
1074 ``websockets.http`` to :mod:`websockets.datastructures`. If you're using
1075 them, you should adjust the import path.
1076
1077 * The ``client``, ``server``, ``protocol``, and ``auth`` modules were
1078 moved from the ``websockets`` package to a ``websockets.legacy``
1079 sub-package. Despite the name, they're still fully supported.
1080
1081 * The ``framing``, ``handshake``, ``headers``, ``http``, and ``uri``
1082 modules in the ``websockets`` package are deprecated. These modules
1083 provided low-level APIs for reuse by other projects, but they didn't
1084 reach that goal. Keeping these APIs public makes it more difficult to
1085 improve websockets.
1086
1087 These changes pave the path for a refactoring that should be a transparent
1088 upgrade for most uses and facilitate integration by other projects.
1089
1090 .. admonition:: Convenience imports from ``websockets`` are performed lazily.
1091 :class: note
1092
1093 While Python supports this, tools relying on static code analysis don't.
1094 This breaks auto-completion in an IDE or type checking with mypy_.
1095
1096 .. _mypy: https://github.com/python/mypy
1097
1098 If you depend on such tools, use the real import paths, which can be found
1099 in the API documentation, for example::
1100
1101 from websockets.client import connect
1102 from websockets.server import serve
1103
1104 New features
1105 ............
1106
1107 * Added compatibility with Python 3.9.
1108
1109 Improvements
1110 ............
1111
1112 * Added support for IRIs in addition to URIs.
1113
1114 * Added close codes 1012, 1013, and 1014.
1115
1116 * Raised an error when passing a :class:`dict` to
1117 :meth:`~legacy.protocol.WebSocketCommonProtocol.send`.
1118
1119 * Improved error reporting.
1120
1121 Bug fixes
1122 .........
1123
1124 * Fixed sending fragmented, compressed messages.
1125
1126 * Fixed ``Host`` header sent when connecting to an IPv6 address.
1127
1128 * Fixed creating a client or a server with an existing Unix socket.
1129
1130 * Aligned maximum cookie size with popular web browsers.
1131
1132 * Ensured cancellation always propagates, even on Python versions where
1133 :exc:`~asyncio.CancelledError` inherits from :exc:`Exception`.
1134
1135 .. _8.1:
1136
1137 8.1
1138 ---
1139
1140 *November 1, 2019*
1141
1142 New features
1143 ............
1144
1145 * Added compatibility with Python 3.8.
1146
1147 8.0.2
1148 -----
1149
1150 *July 31, 2019*
1151
1152 Bug fixes
1153 .........
1154
1155 * Restored the ability to pass a socket with the ``sock`` parameter of
1156 :func:`~legacy.server.serve`.
1157
1158 * Removed an incorrect assertion when a connection drops.
1159
1160 8.0.1
1161 -----
1162
1163 *July 21, 2019*
1164
1165 Bug fixes
1166 .........
1167
1168 * Restored the ability to import ``WebSocketProtocolError`` from
1169 ``websockets``.
1170
1171 .. _8.0:
1172
1173 8.0
1174 ---
1175
1176 *July 7, 2019*
1177
1178 Backwards-incompatible changes
1179 ..............................
1180
1181 .. admonition:: websockets 8.0 requires Python ≥ 3.6.
1182 :class: tip
1183
1184 websockets 7.0 is the last version supporting Python 3.4 and 3.5.
1185
1186 .. admonition:: ``process_request`` is now expected to be a coroutine.
1187 :class: note
1188
1189 If you're passing a ``process_request`` argument to
1190 :func:`~legacy.server.serve` or
1191 :class:`~legacy.server.WebSocketServerProtocol`, or if you're overriding
1192 :meth:`~legacy.server.WebSocketServerProtocol.process_request` in a
1193 subclass, define it with ``async def`` instead of ``def``. Previously, both
1194 were supported.
1195
1196 For backwards compatibility, functions are still accepted, but mixing
1197 functions and coroutines won't work in some inheritance scenarios.
1198
1199 .. admonition:: ``max_queue`` must be :obj:`None` to disable the limit.
1200 :class: note
1201
1202 If you were setting ``max_queue=0`` to make the queue of incoming messages
1203 unbounded, change it to ``max_queue=None``.
1204
1205 .. admonition:: The ``host``, ``port``, and ``secure`` attributes
1206 of :class:`~legacy.protocol.WebSocketCommonProtocol` are deprecated.
1207 :class: note
1208
1209 Use :attr:`~legacy.protocol.WebSocketCommonProtocol.local_address` in
1210 servers and
1211 :attr:`~legacy.protocol.WebSocketCommonProtocol.remote_address` in clients
1212 instead of ``host`` and ``port``.
1213
1214 .. admonition:: ``WebSocketProtocolError`` is renamed
1215 to :exc:`~exceptions.ProtocolError`.
1216 :class: note
1217
1218 An alias provides backwards compatibility.
1219
1220 .. admonition:: ``read_response()`` now returns the reason phrase.
1221 :class: note
1222
1223 If you're using this low-level API, you must change your code.
1224
1225 New features
1226 ............
1227
1228 * Added :func:`~legacy.auth.basic_auth_protocol_factory` to enforce HTTP Basic
1229 Auth on the server side.
1230
1231 * :func:`~legacy.client.connect` handles redirects from the server during the
1232 handshake.
1233
1234 * :func:`~legacy.client.connect` supports overriding ``host`` and ``port``.
1235
1236 * Added :func:`~legacy.client.unix_connect` for connecting to Unix sockets.
1237
1238 * Added support for asynchronous generators
1239 in :meth:`~legacy.protocol.WebSocketCommonProtocol.send`
1240 to generate fragmented messages incrementally.
1241
1242 * Enabled readline in the interactive client.
1243
1244 * Added type hints (:pep:`484`).
1245
1246 * Added a FAQ to the documentation.
1247
1248 * Added documentation for extensions.
1249
1250 * Documented how to optimize memory usage.
1251
1252 Improvements
1253 ............
1254
1255 * :meth:`~legacy.protocol.WebSocketCommonProtocol.send`,
1256 :meth:`~legacy.protocol.WebSocketCommonProtocol.ping`, and
1257 :meth:`~legacy.protocol.WebSocketCommonProtocol.pong` support bytes-like
1258 types :class:`bytearray` and :class:`memoryview` in addition to
1259 :class:`bytes`.
1260
1261 * Added :exc:`~exceptions.ConnectionClosedOK` and
1262 :exc:`~exceptions.ConnectionClosedError` subclasses of
1263 :exc:`~exceptions.ConnectionClosed` to tell apart normal connection
1264 termination from errors.
1265
1266 * Changed :meth:`WebSocketServer.close() <legacy.server.WebSocketServer.close>`
1267 to perform a proper closing handshake instead of failing the connection.
1268
1269 * Improved error messages when HTTP parsing fails.
1270
1271 * Improved API documentation.
1272
1273 Bug fixes
1274 .........
1275
1276 * Prevented spurious log messages about :exc:`~exceptions.ConnectionClosed`
1277 exceptions in keepalive ping task. If you were using ``ping_timeout=None``
1278 as a workaround, you can remove it.
1279
1280 * Avoided a crash when a ``extra_headers`` callable returns :obj:`None`.
1281
1282 .. _7.0:
1283
1284 7.0
1285 ---
1286
1287 *November 1, 2018*
1288
1289 Backwards-incompatible changes
1290 ..............................
1291
1292 .. admonition:: Keepalive is enabled by default.
1293 :class: important
1294
1295 websockets now sends Ping frames at regular intervals and closes the
1296 connection if it doesn't receive a matching Pong frame.
1297 See :class:`~legacy.protocol.WebSocketCommonProtocol` for details.
1298
1299 .. admonition:: Termination of connections by :meth:`WebSocketServer.close()
1300 <legacy.server.WebSocketServer.close>` changes.
1301 :class: caution
1302
1303 Previously, connections handlers were canceled. Now, connections are
1304 closed with close code 1001 (going away).
1305
1306 From the perspective of the connection handler, this is the same as if the
1307 remote endpoint was disconnecting. This removes the need to prepare for
1308 :exc:`~asyncio.CancelledError` in connection handlers.
1309
1310 You can restore the previous behavior by adding the following line at the
1311 beginning of connection handlers::
1312
1313 def handler(websocket, path):
1314 closed = asyncio.ensure_future(websocket.wait_closed())
1315 closed.add_done_callback(lambda task: task.cancel())
1316
1317 .. admonition:: Calling :meth:`~legacy.protocol.WebSocketCommonProtocol.recv`
1318 concurrently raises a :exc:`RuntimeError`.
1319 :class: note
1320
1321 Concurrent calls lead to non-deterministic behavior because there are no
1322 guarantees about which coroutine will receive which message.
1323
1324 .. admonition:: The ``timeout`` argument of :func:`~legacy.server.serve`
1325 and :func:`~legacy.client.connect` is renamed to ``close_timeout`` .
1326 :class: note
1327
1328 This prevents confusion with ``ping_timeout``.
1329
1330 For backwards compatibility, ``timeout`` is still supported.
1331
1332 .. admonition:: The ``origins`` argument of :func:`~legacy.server.serve`
1333 changes.
1334 :class: note
1335
1336 Include :obj:`None` in the list rather than ``''`` to allow requests that
1337 don't contain an Origin header.
1338
1339 .. admonition:: Pending pings aren't canceled when the connection is closed.
1340 :class: note
1341
1342 A ping — as in ``ping = await websocket.ping()`` — for which no pong was
1343 received yet used to be canceled when the connection is closed, so that
1344 ``await ping`` raised :exc:`~asyncio.CancelledError`.
1345
1346 Now ``await ping`` raises :exc:`~exceptions.ConnectionClosed` like other
1347 public APIs.
1348
1349 New features
1350 ............
1351
1352 * Added ``process_request`` and ``select_subprotocol`` arguments to
1353 :func:`~legacy.server.serve` and
1354 :class:`~legacy.server.WebSocketServerProtocol` to facilitate customization of
1355 :meth:`~legacy.server.WebSocketServerProtocol.process_request` and
1356 :meth:`~legacy.server.WebSocketServerProtocol.select_subprotocol`.
1357
1358 * Added support for sending fragmented messages.
1359
1360 * Added the :meth:`~legacy.protocol.WebSocketCommonProtocol.wait_closed`
1361 method to protocols.
1362
1363 * Added an interactive client: ``python -m websockets <uri>``.
1364
1365 Improvements
1366 ............
1367
1368 * Improved handling of multiple HTTP headers with the same name.
1369
1370 * Improved error messages when a required HTTP header is missing.
1371
1372 Bug fixes
1373 .........
1374
1375 * Fixed a data loss bug in
1376 :meth:`~legacy.protocol.WebSocketCommonProtocol.recv`:
1377 canceling it at the wrong time could result in messages being dropped.
1378
1379 .. _6.0:
1380
1381 6.0
1382 ---
1383
1384 *July 16, 2018*
1385
1386 Backwards-incompatible changes
1387 ..............................
1388
1389 .. admonition:: The :class:`~datastructures.Headers` class is introduced and
1390 several APIs are updated to use it.
1391 :class: caution
1392
1393 * The ``request_headers`` argument of
1394 :meth:`~legacy.server.WebSocketServerProtocol.process_request` is now a
1395 :class:`~datastructures.Headers` instead of an
1396 ``http.client.HTTPMessage``.
1397
1398 * The ``request_headers`` and ``response_headers`` attributes of
1399 :class:`~legacy.protocol.WebSocketCommonProtocol` are now
1400 :class:`~datastructures.Headers` instead of ``http.client.HTTPMessage``.
1401
1402 * The ``raw_request_headers`` and ``raw_response_headers`` attributes of
1403 :class:`~legacy.protocol.WebSocketCommonProtocol` are removed. Use
1404 :meth:`~datastructures.Headers.raw_items` instead.
1405
1406 * Functions defined in the ``handshake`` module now receive
1407 :class:`~datastructures.Headers` in argument instead of ``get_header``
1408 or ``set_header`` functions. This affects libraries that rely on
1409 low-level APIs.
1410
1411 * Functions defined in the ``http`` module now return HTTP headers as
1412 :class:`~datastructures.Headers` instead of lists of ``(name, value)``
1413 pairs.
1414
1415 Since :class:`~datastructures.Headers` and ``http.client.HTTPMessage``
1416 provide similar APIs, much of the code dealing with HTTP headers won't
1417 require changes.
1418
1419 New features
1420 ............
1421
1422 * Added compatibility with Python 3.7.
1423
1424 5.0.1
1425 -----
1426
1427 *May 24, 2018*
1428
1429 Bug fixes
1430 .........
1431
1432 * Fixed a regression in 5.0 that broke some invocations of
1433 :func:`~legacy.server.serve` and :func:`~legacy.client.connect`.
1434
1435 .. _5.0:
1436
1437 5.0
1438 ---
1439
1440 *May 22, 2018*
1441
1442 Security fix
1443 ............
1444
1445 .. admonition:: websockets 5.0 fixes a security issue introduced in 4.0.
1446 :class: danger
1447
1448 Version 4.0 was vulnerable to denial of service by memory exhaustion
1449 because it didn't enforce ``max_size`` when decompressing compressed
1450 messages (`CVE-2018-1000518`_).
1451
1452 .. _CVE-2018-1000518: https://nvd.nist.gov/vuln/detail/CVE-2018-1000518
1453
1454 Backwards-incompatible changes
1455 ..............................
1456
1457 .. admonition:: A ``user_info`` field is added to the return value of
1458 ``parse_uri`` and ``WebSocketURI``.
1459 :class: note
1460
1461 If you're unpacking ``WebSocketURI`` into four variables, adjust your code
1462 to account for that fifth field.
1463
1464 New features
1465 ............
1466
1467 * :func:`~legacy.client.connect` performs HTTP Basic Auth when the URI contains
1468 credentials.
1469
1470 * :func:`~legacy.server.unix_serve` can be used as an asynchronous context
1471 manager on Python ≥ 3.5.1.
1472
1473 * Added the :attr:`~legacy.protocol.WebSocketCommonProtocol.closed` property
1474 to protocols.
1475
1476 * Added new examples in the documentation.
1477
1478 Improvements
1479 ............
1480
1481 * Iterating on incoming messages no longer raises an exception when the
1482 connection terminates with close code 1001 (going away).
1483
1484 * A plain HTTP request now receives a 426 Upgrade Required response and
1485 doesn't log a stack trace.
1486
1487 * If a :meth:`~legacy.protocol.WebSocketCommonProtocol.ping` doesn't receive a
1488 pong, it's canceled when the connection is closed.
1489
1490 * Reported the cause of :exc:`~exceptions.ConnectionClosed` exceptions.
1491
1492 * Stopped logging stack traces when the TCP connection dies prematurely.
1493
1494 * Prevented writing to a closing TCP connection during unclean shutdowns.
1495
1496 * Made connection termination more robust to network congestion.
1497
1498 * Prevented processing of incoming frames after failing the connection.
1499
1500 * Updated documentation with new features from Python 3.6.
1501
1502 * Improved several sections of the documentation.
1503
1504 Bug fixes
1505 .........
1506
1507 * Prevented :exc:`TypeError` due to missing close code on connection close.
1508
1509 * Fixed a race condition in the closing handshake that raised
1510 :exc:`~exceptions.InvalidState`.
1511
1512 4.0.1
1513 -----
1514
1515 *November 2, 2017*
1516
1517 Bug fixes
1518 .........
1519
1520 * Fixed issues with the packaging of the 4.0 release.
1521
1522 .. _4.0:
1523
1524 4.0
1525 ---
1526
1527 *November 2, 2017*
1528
1529 Backwards-incompatible changes
1530 ..............................
1531
1532 .. admonition:: websockets 4.0 requires Python ≥ 3.4.
1533 :class: tip
1534
1535 websockets 3.4 is the last version supporting Python 3.3.
1536
1537 .. admonition:: Compression is enabled by default.
1538 :class: important
1539
1540 In August 2017, Firefox and Chrome support the permessage-deflate
1541 extension, but not Safari and IE.
1542
1543 Compression should improve performance but it increases RAM and CPU use.
1544
1545 If you want to disable compression, add ``compression=None`` when calling
1546 :func:`~legacy.server.serve` or :func:`~legacy.client.connect`.
1547
1548 .. admonition:: The ``state_name`` attribute of protocols is deprecated.
1549 :class: note
1550
1551 Use ``protocol.state.name`` instead of ``protocol.state_name``.
1552
1553 New features
1554 ............
1555
1556 * :class:`~legacy.protocol.WebSocketCommonProtocol` instances can be used as
1557 asynchronous iterators on Python ≥ 3.6. They yield incoming messages.
1558
1559 * Added :func:`~legacy.server.unix_serve` for listening on Unix sockets.
1560
1561 * Added the :attr:`~legacy.server.WebSocketServer.sockets` attribute to the
1562 return value of :func:`~legacy.server.serve`.
1563
1564 * Allowed ``extra_headers`` to override ``Server`` and ``User-Agent`` headers.
1565
1566 Improvements
1567 ............
1568
1569 * Reorganized and extended documentation.
1570
1571 * Rewrote connection termination to increase robustness in edge cases.
1572
1573 * Reduced verbosity of "Failing the WebSocket connection" logs.
1574
1575 Bug fixes
1576 .........
1577
1578 * Aborted connections if they don't close within the configured ``timeout``.
1579
1580 * Stopped leaking pending tasks when :meth:`~asyncio.Task.cancel` is called on
1581 a connection while it's being closed.
1582
1583 .. _3.4:
1584
1585 3.4
1586 ---
1587
1588 *August 20, 2017*
1589
1590 Backwards-incompatible changes
1591 ..............................
1592
1593 .. admonition:: ``InvalidStatus`` is replaced
1594 by :class:`~exceptions.InvalidStatusCode`.
1595 :class: note
1596
1597 This exception is raised when :func:`~legacy.client.connect` receives an invalid
1598 response status code from the server.
1599
1600 New features
1601 ............
1602
1603 * :func:`~legacy.server.serve` can be used as an asynchronous context manager
1604 on Python ≥ 3.5.1.
1605
1606 * Added support for customizing handling of incoming connections with
1607 :meth:`~legacy.server.WebSocketServerProtocol.process_request`.
1608
1609 * Made read and write buffer sizes configurable.
1610
1611 Improvements
1612 ............
1613
1614 * Renamed :func:`~legacy.server.serve` and :func:`~legacy.client.connect`'s
1615 ``klass`` argument to ``create_protocol`` to reflect that it can also be a
1616 callable. For backwards compatibility, ``klass`` is still supported.
1617
1618 * Rewrote HTTP handling for simplicity and performance.
1619
1620 * Added an optional C extension to speed up low-level operations.
1621
1622 Bug fixes
1623 .........
1624
1625 * Providing a ``sock`` argument to :func:`~legacy.client.connect` no longer
1626 crashes.
1627
1628 .. _3.3:
1629
1630 3.3
1631 ---
1632
1633 *March 29, 2017*
1634
1635 New features
1636 ............
1637
1638 * Ensured compatibility with Python 3.6.
1639
1640 Improvements
1641 ............
1642
1643 * Reduced noise in logs caused by connection resets.
1644
1645 Bug fixes
1646 .........
1647
1648 * Avoided crashing on concurrent writes on slow connections.
1649
1650 .. _3.2:
1651
1652 3.2
1653 ---
1654
1655 *August 17, 2016*
1656
1657 New features
1658 ............
1659
1660 * Added ``timeout``, ``max_size``, and ``max_queue`` arguments to
1661 :func:`~legacy.client.connect` and :func:`~legacy.server.serve`.
1662
1663 Improvements
1664 ............
1665
1666 * Made server shutdown more robust.
1667
1668 .. _3.1:
1669
1670 3.1
1671 ---
1672
1673 *April 21, 2016*
1674
1675 New features
1676 ............
1677
1678 * Added flow control for incoming data.
1679
1680 Bug fixes
1681 .........
1682
1683 * Avoided a warning when closing a connection before the opening handshake.
1684
1685 .. _3.0:
1686
1687 3.0
1688 ---
1689
1690 *December 25, 2015*
1691
1692 Backwards-incompatible changes
1693 ..............................
1694
1695 .. admonition:: :meth:`~legacy.protocol.WebSocketCommonProtocol.recv` now
1696 raises an exception when the connection is closed.
1697 :class: caution
1698
1699 :meth:`~legacy.protocol.WebSocketCommonProtocol.recv` used to return
1700 :obj:`None` when the connection was closed. This required checking the
1701 return value of every call::
1702
1703 message = await websocket.recv()
1704 if message is None:
1705 return
1706
1707 Now it raises a :exc:`~exceptions.ConnectionClosed` exception instead.
1708 This is more Pythonic. The previous code can be simplified to::
1709
1710 message = await websocket.recv()
1711
1712 When implementing a server, there's no strong reason to handle such
1713 exceptions. Let them bubble up, terminate the handler coroutine, and the
1714 server will simply ignore them.
1715
1716 In order to avoid stranding projects built upon an earlier version, the
1717 previous behavior can be restored by passing ``legacy_recv=True`` to
1718 :func:`~legacy.server.serve`, :func:`~legacy.client.connect`,
1719 :class:`~legacy.server.WebSocketServerProtocol`, or
1720 :class:`~legacy.client.WebSocketClientProtocol`.
1721
1722 New features
1723 ............
1724
1725 * :func:`~legacy.client.connect` can be used as an asynchronous context manager
1726 on Python ≥ 3.5.1.
1727
1728 * :meth:`~legacy.protocol.WebSocketCommonProtocol.ping` and
1729 :meth:`~legacy.protocol.WebSocketCommonProtocol.pong` support data passed as
1730 :class:`str` in addition to :class:`bytes`.
1731
1732 * Made ``state_name`` attribute on protocols a public API.
1733
1734 Improvements
1735 ............
1736
1737 * Updated documentation with ``await`` and ``async`` syntax from Python 3.5.
1738
1739 * Worked around an :mod:`asyncio` bug affecting connection termination under
1740 load.
1741
1742 * Improved documentation.
1743
1744 .. _2.7:
1745
1746 2.7
1747 ---
1748
1749 *November 18, 2015*
1750
1751 New features
1752 ............
1753
1754 * Added compatibility with Python 3.5.
1755
1756 Improvements
1757 ............
1758
1759 * Refreshed documentation.
1760
1761 .. _2.6:
1762
1763 2.6
1764 ---
1765
1766 *August 18, 2015*
1767
1768 New features
1769 ............
1770
1771 * Added ``local_address`` and ``remote_address`` attributes on protocols.
1772
1773 * Closed open connections with code 1001 when a server shuts down.
1774
1775 Bug fixes
1776 .........
1777
1778 * Avoided TCP fragmentation of small frames.
1779
1780 .. _2.5:
1781
1782 2.5
1783 ---
1784
1785 *July 28, 2015*
1786
1787 New features
1788 ............
1789
1790 * Provided access to handshake request and response HTTP headers.
1791
1792 * Allowed customizing handshake request and response HTTP headers.
1793
1794 * Added support for running on a non-default event loop.
1795
1796 Improvements
1797 ............
1798
1799 * Improved documentation.
1800
1801 * Sent a 403 status code instead of 400 when request Origin isn't allowed.
1802
1803 * Clarified that the closing handshake can be initiated by the client.
1804
1805 * Set the close code and reason more consistently.
1806
1807 * Strengthened connection termination.
1808
1809 Bug fixes
1810 .........
1811
1812 * Canceling :meth:`~legacy.protocol.WebSocketCommonProtocol.recv` no longer
1813 drops the next message.
1814
1815 .. _2.4:
1816
1817 2.4
1818 ---
1819
1820 *January 31, 2015*
1821
1822 New features
1823 ............
1824
1825 * Added support for subprotocols.
1826
1827 * Added ``loop`` argument to :func:`~legacy.client.connect` and
1828 :func:`~legacy.server.serve`.
1829
1830 .. _2.3:
1831
1832 2.3
1833 ---
1834
1835 *November 3, 2014*
1836
1837 Improvements
1838 ............
1839
1840 * Improved compliance of close codes.
1841
1842 .. _2.2:
1843
1844 2.2
1845 ---
1846
1847 *July 28, 2014*
1848
1849 New features
1850 ............
1851
1852 * Added support for limiting message size.
1853
1854 .. _2.1:
1855
1856 2.1
1857 ---
1858
1859 *April 26, 2014*
1860
1861 New features
1862 ............
1863
1864 * Added ``host``, ``port`` and ``secure`` attributes on protocols.
1865
1866 * Added support for providing and checking Origin_.
1867
1868 .. _Origin: https://datatracker.ietf.org/doc/html/rfc6455.html#section-10.2
1869
1870 .. _2.0:
1871
1872 2.0
1873 ---
1874
1875 *February 16, 2014*
1876
1877 Backwards-incompatible changes
1878 ..............................
1879
1880 .. admonition:: :meth:`~legacy.protocol.WebSocketCommonProtocol.send`,
1881 :meth:`~legacy.protocol.WebSocketCommonProtocol.ping`, and
1882 :meth:`~legacy.protocol.WebSocketCommonProtocol.pong` are now coroutines.
1883 :class: caution
1884
1885 They used to be functions.
1886
1887 Instead of::
1888
1889 websocket.send(message)
1890
1891 you must write::
1892
1893 await websocket.send(message)
1894
1895 New features
1896 ............
1897
1898 * Added flow control for outgoing data.
1899
1900 .. _1.0:
1901
1902 1.0
1903 ---
1904
1905 *November 14, 2013*
1906
1907 New features
1908 ............
1909
1910 * Initial public release.