Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize empty return #44

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.310',
version='0.0.311',
license='MIT',
author='nggit',
author_email='[email protected]',
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.310'
__version__ = '0.0.311'

from .tremolo import Tremolo # noqa: E402
from . import exceptions # noqa: E402,F401
Expand Down
16 changes: 9 additions & 7 deletions tremolo/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async def _handle_response(self, func, options={}):
if isinstance(data, str):
data = data.encode(encoding[0])

if no_content or data == b'':
if no_content:
self.response.set_header(b'Connection', b'close')
else:
if self.response.http_chunked:
Expand Down Expand Up @@ -265,15 +265,17 @@ async def _handle_response(self, func, options={}):
if not isinstance(options, dict):
return

if data == b'' or self.request.method == b'HEAD' or no_content:
if self.request.method == b'HEAD' or no_content:
await self.response.write(None)
return

self.set_watermarks(high=options['buffer_size'] * 4,
low=options['buffer_size'] // 2)
await self.response.write(data,
rate=options['rate'],
buffer_size=options['buffer_size'])
if data != b'':
self.set_watermarks(high=options['buffer_size'] * 4,
low=options['buffer_size'] // 2)
await self.response.write(data,
rate=options['rate'],
buffer_size=options['buffer_size'])

await self.response.write(b'', throttle=False)

self.response.close(keepalive=True)
Expand Down