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