Skip to content

Commit 27bf079

Browse files
committed
Added docs about the video streaming example and removed content_type parameter from XMixedReplaceResponse
1 parent ec89785 commit 27bf079

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/examples.rst

+17
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ This might change in the future, but for now, it is recommended to use Websocket
352352
:emphasize-lines: 12,20,65-72,88,99
353353
:linenos:
354354

355+
Custom response types e.g. video streaming
356+
------------------------------------------
357+
358+
The built-in response types may not always meet your specific requirements. In such cases, you can define custom response types and implement
359+
the necessary logic.
360+
361+
The example below demonstrates a ``XMixedReplaceResponse`` class, which uses the ``multipart/x-mixed-replace`` content type to stream video frames
362+
from a camera, similar to a CCTV system.
363+
364+
To ensure the server remains responsive, a global list of open connections is maintained. By running tasks asynchronously, the server can stream
365+
video to multiple clients while simultaneously handling other requests.
366+
367+
.. literalinclude:: ../examples/httpserver_video_stream.py
368+
:caption: examples/httpserver_video_stream.py
369+
:emphasize-lines: 31-77,92
370+
:linenos:
371+
355372
Multiple servers
356373
----------------
357374

examples/httpserver_video_stream.py

-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ def __init__(
3737
status: Union[Status, Tuple[int, str]] = OK_200,
3838
headers: Union[Headers, Dict[str, str]] = None,
3939
cookies: Dict[str, str] = None,
40-
content_type: str = None,
4140
) -> None:
4241
super().__init__(
4342
request=request,
4443
headers=headers,
4544
cookies=cookies,
4645
status=status,
47-
content_type=content_type,
4846
)
4947
self._boundary = self._get_random_boundary()
5048
self._headers.setdefault(

0 commit comments

Comments
 (0)