Skip to content

Commit

Permalink
optimize empty return
Browse files Browse the repository at this point in the history
  • Loading branch information
nggit committed Nov 26, 2023
1 parent b0f8304 commit c2661d6
Showing 1 changed file with 9 additions and 7 deletions.
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

0 comments on commit c2661d6

Please sign in to comment.