From 89ec439d3e2be6842e04dcf622d735d5c11b7315 Mon Sep 17 00:00:00 2001 From: "Maxime Alves LIRMM@home" Date: Thu, 22 Apr 2021 22:05:10 +0200 Subject: [PATCH] ajout du header x-args-required et x-args-optional --- halfapi/lib/domain_middleware.py | 9 +++++++++ halfapi/lib/routes.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index 448535d..46fccc4 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -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 diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index 0c0be13..d2fa21a 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -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__)