99
1010from aiohttp import web
1111
12+ from . import page
1213from .adaptor import ws as ws_adaptor
1314from .page import make_applications , render_page
1415from .remote_access import start_remote_access_service
1516from .tornado import open_webbrowser_on_server_started
1617from .utils import cdn_validation , print_listen_address
1718from ..session import register_session_implement_for_target , Session
1819from ..session .base import get_session_info_from_headers
19- from ..utils import get_free_port , STATIC_PATH
20+ from ..utils import get_free_port , STATIC_PATH , parse_file_size
2021
2122logger = logging .getLogger (__name__ )
2223
@@ -125,7 +126,7 @@ async def wshandle(request: web.Request):
125126
126127
127128def webio_handler (applications , cdn = True , reconnect_timeout = 0 , allowed_origins = None , check_origin = None ,
128- websocket_settings = None ):
129+ max_payload_size = '200M' , websocket_settings = None ):
129130 """Get the `Request Handler <https://docs.aiohttp.org/en/stable/web_quickstart.html#aiohttp-web-handler>`_ coroutine for running PyWebIO applications in aiohttp.
130131 The handler communicates with the browser by WebSocket protocol.
131132
@@ -139,6 +140,9 @@ def webio_handler(applications, cdn=True, reconnect_timeout=0, allowed_origins=N
139140
140141 websocket_settings = websocket_settings or {}
141142
143+ page .MAX_PAYLOAD_SIZE = max_payload_size = parse_file_size (max_payload_size )
144+ websocket_settings .setdefault ('max_msg_size' , max_payload_size )
145+
142146 cdn = cdn_validation (cdn , 'error' )
143147
144148 if check_origin is None :
@@ -170,10 +174,12 @@ def start_server(applications, port=0, host='', debug=False,
170174 reconnect_timeout = 0 ,
171175 allowed_origins = None , check_origin = None ,
172176 auto_open_webbrowser = False ,
177+ max_payload_size = '200M' ,
173178 websocket_settings = None ,
174179 ** aiohttp_settings ):
175180 """Start a aiohttp server to provide the PyWebIO application as a web service.
176181
182+
177183 :param dict websocket_settings: The parameters passed to the constructor of ``aiohttp.web.WebSocketResponse``.
178184 For details, please refer: https://docs.aiohttp.org/en/stable/web_reference.html#websocketresponse
179185 :param aiohttp_settings: Additional keyword arguments passed to the constructor of ``aiohttp.web.Application``.
@@ -192,7 +198,8 @@ def start_server(applications, port=0, host='', debug=False,
192198 cdn = cdn_validation (cdn , 'warn' )
193199
194200 handler = webio_handler (applications , cdn = cdn , allowed_origins = allowed_origins , reconnect_timeout = reconnect_timeout ,
195- check_origin = check_origin , websocket_settings = websocket_settings )
201+ check_origin = check_origin , max_payload_size = max_payload_size ,
202+ websocket_settings = websocket_settings )
196203
197204 app = web .Application (** aiohttp_settings )
198205 app .router .add_routes ([web .get ('/' , handler )])
0 commit comments