Minor performance improvement by not creating a new function for each request
@@ -723,9 +723,7 @@ class HttpTransport(Invoker):
logging.getLogger("aiohttp.access").setLevel(logging.WARNING)
- @web.middleware
- async def middleware(request: web.Request, handler: Callable) -> Union[web.Response, web.FileResponse]:
- async def func() -> Union[web.Response, web.FileResponse]:
+ async def request_handler_func(request: web.Request, handler: Callable) -> Union[web.Response, web.FileResponse]:
response: Union[web.Response, web.FileResponse]
request_ip = RequestHandler.get_request_ip(request, context)
@@ -871,9 +869,11 @@ class HttpTransport(Invoker):
return response
+ @web.middleware
+ async def middleware(request: web.Request, handler: Callable) -> Union[web.Response, web.FileResponse]:
increase_execution_context_value("http_current_tasks")
increase_execution_context_value("http_total_tasks")
- task = asyncio.ensure_future(func())
+ task = asyncio.ensure_future(request_handler_func(request, handler))
context["_http_active_requests"] = context.get("_http_active_requests", set())
context["_http_active_requests"].add(task)
try:
