Add current request context to get_url helper (#38602)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-08-09 14:07:31 +02:00
1 parent 53b729a0d1
commit 20710d8605
5 files changed
+252 -8

No files matched your search

@@ -0,0 +1,20 @@
"""Middleware to set the request context."""
from aiohttp.web import middleware
from homeassistant.core import callback
# mypy: allow-untyped-defs
@callback
def setup_request_context(app, context):
"""Create request context middleware for the app."""
@middleware
async def request_context_middleware(request, handler):
"""Request context middleware."""
context.set(request)
return await handler(request)
app.middlewares.append(request_context_middleware)