Re-use variable

This commit is contained in:
Unrud 2022-01-18 18:20:14 +01:00
parent e0adecf30c
commit 1336c02079

View File

@ -123,6 +123,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
) -> _IntermediateResponse: ) -> _IntermediateResponse:
time_begin = datetime.datetime.now() time_begin = datetime.datetime.now()
request_method = environ["REQUEST_METHOD"].upper() request_method = environ["REQUEST_METHOD"].upper()
unsafe_path = environ.get("PATH_INFO", "")
"""Manage a request.""" """Manage a request."""
def response(status: int, headers: types.WSGIResponseHeaders, def response(status: int, headers: types.WSGIResponseHeaders,
@ -157,15 +158,12 @@ 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( logger.info("%s response status for %r%s in %.3f seconds: %s",
"%s response status for %r%s in %.3f seconds: %s", request_method, unsafe_path, depthinfo,
environ["REQUEST_METHOD"], environ.get("PATH_INFO", ""), (time_end - time_begin).total_seconds(), status_text)
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
unsafe_path = environ.get("PATH_INFO", "")
remote_host = "unknown" remote_host = "unknown"
if environ.get("REMOTE_HOST"): if environ.get("REMOTE_HOST"):
remote_host = repr(environ["REMOTE_HOST"]) remote_host = repr(environ["REMOTE_HOST"])