log size of answer if given
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user