Skip to content

Commit

Permalink
change unnecessary closure into plain function
Browse files Browse the repository at this point in the history
  • Loading branch information
byewokko committed Oct 25, 2024
1 parent db205f5 commit f380c4d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions asab/web/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,6 @@ def __init__(self, websvc: WebService, config_section_name: str, config: typing.
preflight_paths = re.split(r"[,\s]+", preflight_str, re.MULTILINE)
self.add_preflight_handlers(preflight_paths)

@aiohttp.web.middleware
async def set_request_context(request: aiohttp.web.Request, handler):
"""
Make sure that the incoming aiohttp.web.Request is available via Request context variable
"""
request_ctx = Request.set(request)
try:
return await handler(request)
finally:
Request.reset(request_ctx)

self.WebApp.middlewares.append(set_request_context)


Expand Down Expand Up @@ -227,3 +216,15 @@ def get_ports(self) -> typing.List[str]:
for addr, port, ssl_context in self._listen:
ports.append(port)
return ports


@aiohttp.web.middleware
async def set_request_context(request: aiohttp.web.Request, handler):
"""
Make sure that the incoming aiohttp.web.Request is available via Request context variable
"""
request_ctx = Request.set(request)
try:
return await handler(request)
finally:
Request.reset(request_ctx)

0 comments on commit f380c4d

Please sign in to comment.