log size of answer if given

This commit is contained in:
Peter Bieringer
2025-10-04 11:48:08 +02:00
parent 17b67e8998
commit 50a6b8462d

View File

@@ -164,6 +164,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
answer: Union[None, str, bytes]) -> _IntermediateResponse: answer: Union[None, str, bytes]) -> _IntermediateResponse:
"""Helper to create response from internal types.WSGIResponse""" """Helper to create response from internal types.WSGIResponse"""
headers = dict(headers) headers = dict(headers)
content_encoding = "plain"
# Set content length # Set content length
answers = [] answers = []
if answer is not None: if answer is not None:
@@ -183,6 +184,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
answer = zcomp.compress(answer) + zcomp.flush() answer = zcomp.compress(answer) + zcomp.flush()
headers["Content-Encoding"] = "gzip" headers["Content-Encoding"] = "gzip"
content_encoding = "gzip"
headers["Content-Length"] = str(len(answer)) headers["Content-Length"] = str(len(answer))
answers.append(answer) answers.append(answer)
@@ -194,9 +196,14 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
time_end = datetime.datetime.now() time_end = datetime.datetime.now()
status_text = "%d %s" % ( status_text = "%d %s" % (
status, client.responses.get(status, "Unknown")) status, client.responses.get(status, "Unknown"))
logger.info("%s response status for %r%s in %.3f seconds: %s", if answer is not None:
request_method, unsafe_path, depthinfo, logger.info("%s response status for %r%s in %.3f seconds %s %s bytes: %s",
(time_end - time_begin).total_seconds(), status_text) request_method, unsafe_path, depthinfo,
(time_end - time_begin).total_seconds(), content_encoding, str(len(answer)), status_text)
else:
logger.info("%s response status for %r%s in %.3f seconds: %s",
request_method, unsafe_path, depthinfo,
(time_end - time_begin).total_seconds(), status_text)
# Return response content # Return response content
return status_text, list(headers.items()), answers return status_text, list(headers.items()), answers