Browse Source

fix websocket not closed properly in fastapi backend

wangweimin 4 years ago
parent
commit
c4d990eef4
1 changed files with 6 additions and 0 deletions
  1. 6 0
      pywebio/platform/fastapi.py

+ 6 - 0
pywebio/platform/fastapi.py

@@ -78,6 +78,8 @@ def _webio_routes(applications, cdn, check_origin_func):
         while True:
             try:
                 msg = await websocket.receive()
+                if msg["type"] == "websocket.disconnect":
+                    raise WebSocketDisconnect(msg["code"])
                 text, binary = msg.get('text'), msg.get('bytes')
                 event = None
                 if text:
@@ -107,6 +109,8 @@ def webio_routes(applications, cdn=True, allowed_origins=None, check_origin=None
 
     The arguments of ``webio_routes()`` have the same meaning as for :func:`pywebio.platform.fastapi.start_server`
 
+    .. versionadded:: 1.3
+
     :return: FastAPI/Starlette routes
     """
     try:
@@ -144,6 +148,8 @@ def start_server(applications, port=0, host='',
        For details, please refer: https://www.uvicorn.org/settings/
 
     The rest arguments of ``start_server()`` have the same meaning as for :func:`pywebio.platform.tornado.start_server`
+
+    .. versionadded:: 1.3
     """
     kwargs = locals()