ajout du header x-args-required et x-args-optional

This commit is contained in:
Maxime Alves LIRMM@home 2021-04-22 22:05:10 +02:00
parent b5ef4a12d1
commit 89ec439d3e
2 changed files with 11 additions and 0 deletions

View File

@ -81,4 +81,13 @@ class DomainMiddleware(BaseHTTPMiddleware):
# Set the http header "x-acl" if an acl was used on the route
response.headers['x-acl'] = self.request.scope['acl_pass']
if 'args' in self.request.scope:
# Set the http headers "x-args-required" and "x-args-optional"
if 'required' in self.request.scope['args']:
response.headers['x-args-required'] = \
','.join(self.request.scope['args']['required'])
if 'optional' in self.request.scope['args']:
response.headers['x-args-optional'] = \
','.join(self.request.scope['args']['optional'])
return response

View File

@ -51,6 +51,8 @@ def route_acl_decorator(fct: Callable, params: List[Dict]):
logger.debug(f'ACL OK for current route ({fct} - {param.get("acl")})')
req.scope['acl_pass'] = param['acl'].__name__
if 'args' in param:
req.scope['args'] = param['args']
if 'check' in req.query_params:
return PlainTextResponse(param['acl'].__name__)