From b5ef4a12d14262aba30a41b311a833123fb9ffda Mon Sep 17 00:00:00 2001 From: "Maxime Alves LIRMM@home" Date: Thu, 22 Apr 2021 21:08:53 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20header=20http=20"x-acl"=20qui=20re?= =?UTF-8?q?nseigne=20l'acl=20qui=20a=20pass=C3=A9=20dans=20une=20requ?= =?UTF-8?q?=C3=AAte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- halfapi/lib/domain_middleware.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index e0389ad..448535d 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -32,6 +32,7 @@ class DomainMiddleware(BaseHTTPMiddleware): self.domains = {} self.api = {} self.acl = {} + self.request = None async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: @@ -63,13 +64,21 @@ class DomainMiddleware(BaseHTTPMiddleware): scope_['config'] = {} - request = Request(scope_, receive) - response = await self.dispatch(request, self.call_next) + self.request = Request(scope_, receive) + response = await self.dispatch(self.request, self.call_next) await response(scope_, receive, send) async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: + """ + Call of the route fonction (decorated or not) + """ response = await call_next(request) + + if 'acl_pass' in self.request.scope: + # Set the http header "x-acl" if an acl was used on the route + response.headers['x-acl'] = self.request.scope['acl_pass'] + return response