Skip to content

Commit

Permalink
release 0.0.313 (#48)
Browse files Browse the repository at this point in the history
* fix ASGI app return empty str

* independent max payload size for ws

---------

Co-authored-by: nggit <[email protected]>
  • Loading branch information
nggit and nggit authored Dec 2, 2023
1 parent c7821df commit 8dea666
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion alltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
port=HTTP_PORT,
debug=False,
reload=True,
client_max_body_size=73728))
client_max_body_size=73728,
ws_max_payload_size=73728))
)
processes.append(mp.Process(
target=tremolo.run,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='tremolo',
version='0.0.312',
version='0.0.313',
license='MIT',
author='nggit',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,6 @@ async def reload(request=None, **_):

if __name__ == '__main__':
app.run(HTTP_HOST, port=HTTP_PORT, debug=True, reload=True,
client_max_body_size=73728)
client_max_body_size=73728, ws_max_payload_size=73728)

# END
3 changes: 2 additions & 1 deletion tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ def test_reload(self):
port=HTTP_PORT,
debug=False,
reload=True,
client_max_body_size=73728)
client_max_body_size=73728,
ws_max_payload_size=73728)
)

p.start()
Expand Down
2 changes: 1 addition & 1 deletion tremolo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.0.312'
__version__ = '0.0.313'

from .tremolo import Tremolo # noqa: E402
from . import exceptions # noqa: E402,F401
Expand Down
3 changes: 3 additions & 0 deletions tremolo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
print(' --reload Enable auto reload on code changes')
print(' Intended for development')
print(' --no-ws Disable built-in WebSocket support')
print(' --ws-max-payload-size Maximum payload size for the built-in WebSocket') # noqa: E501
print(' Defaults to 2 * 1048576, or 2MiB')
print(' --log-level Defaults to "DEBUG". See')
print(' https://docs.python.org/3/library/logging.html#levels') # noqa: E501
print(' --download-rate Limits the sending speed to the client') # noqa: E501
Expand Down Expand Up @@ -77,6 +79,7 @@
'--download-rate',
'--upload-rate',
'--buffer-size',
'--ws-max-payload-size',
'--client-max-body-size',
'--client-max-header-size',
'--max-queue-size',
Expand Down
4 changes: 3 additions & 1 deletion tremolo/asgi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ async def send(self, data):
)

if 'more_body' not in data or data['more_body'] is False:
await self.response.write(b'', throttle=False)
await self.response.write(
b'', chunked=self._http_chunked, throttle=False
)
self.response.close(keepalive=True)

self._read = None
Expand Down
4 changes: 2 additions & 2 deletions tremolo/lib/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ async def recv(self):
payload_length = int.from_bytes(await self.request.recv(8),
byteorder='big')

if payload_length > self.protocol.options['client_max_body_size']:
if payload_length > self.protocol.options['ws_max_payload_size']:
raise WebSocketServerClosed(
'%d exceeds maximum payload size (%d)' % (
payload_length,
self.protocol.options['client_max_body_size']),
self.protocol.options['ws_max_payload_size']),
code=1009
)

Expand Down
3 changes: 3 additions & 0 deletions tremolo/tremolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ async def _serve(self, host, port, **options):
worker=context,
debug=options.get('debug', False),
ws=options.get('ws', True),
ws_max_payload_size=options.get(
'ws_max_payload_size', 2 * 1048576
),
download_rate=options.get('download_rate', 1048576),
upload_rate=options.get('upload_rate', 1048576),
buffer_size=options.get('buffer_size', 16 * 1024),
Expand Down

0 comments on commit 8dea666

Please sign in to comment.