DomainMiddleware ne vérifie plus les domaines non concernés par la première partie du path (optimisation vitesse)
This commit is contained in:
parent
795ca3dcc0
commit
a2fb70f84b
|
@ -10,6 +10,7 @@ It defines the following globals :
|
|||
|
||||
"""
|
||||
import logging
|
||||
import time
|
||||
|
||||
# asgi framework
|
||||
from starlette.applications import Starlette
|
||||
|
@ -32,7 +33,7 @@ from halfapi.lib.jwt_middleware import JWTAuthenticationBackend
|
|||
from halfapi.lib.responses import (ORJSONResponse, UnauthorizedResponse,
|
||||
NotFoundResponse, InternalServerErrorResponse, NotImplementedResponse)
|
||||
|
||||
from halfapi.lib.routes import gen_starlette_routes, api_routes, debug_routes
|
||||
from halfapi.lib.routes import gen_starlette_routes, debug_routes
|
||||
from halfapi.lib.schemas import get_api_routes, schema_json, get_acls
|
||||
|
||||
logger = logging.getLogger('uvicorn.asgi')
|
||||
|
|
|
@ -33,6 +33,8 @@ def args_check(fct):
|
|||
@wraps(fct)
|
||||
async def caller(req, *args, **kwargs):
|
||||
if 'check' in req.query_params:
|
||||
""" Check query param should not read the "args"
|
||||
"""
|
||||
return await fct(req, *args, **kwargs)
|
||||
|
||||
if req.method == 'GET':
|
||||
|
|
|
@ -5,6 +5,7 @@ lib/domain.py The domain-scoped utility functions
|
|||
|
||||
import importlib
|
||||
import logging
|
||||
import time
|
||||
from types import ModuleType
|
||||
from typing import Generator, Dict, List
|
||||
|
||||
|
@ -160,7 +161,6 @@ def gen_domain_routes(domain: str, m_dom: ModuleType) -> Generator:
|
|||
The domain must have a routers module in it's root-level.
|
||||
If not, it is considered as empty
|
||||
"""
|
||||
|
||||
m_router = None
|
||||
try:
|
||||
m_router = importlib.import_module('.routers', domain)
|
||||
|
@ -171,6 +171,7 @@ def gen_domain_routes(domain: str, m_dom: ModuleType) -> Generator:
|
|||
if m_router:
|
||||
yield from gen_router_routes(m_router, [domain])
|
||||
|
||||
|
||||
def d_domains(config) -> Dict[str, ModuleType]:
|
||||
"""
|
||||
Parameters:
|
||||
|
|
|
@ -37,12 +37,14 @@ class DomainMiddleware(BaseHTTPMiddleware):
|
|||
|
||||
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
||||
"""
|
||||
Scans routes and acls of each domain in config
|
||||
Scans routes and acls of the domain in the first part of the path
|
||||
"""
|
||||
domain = scope['path'].split('/')[1]
|
||||
|
||||
self.domains = d_domains(self.config)
|
||||
|
||||
for domain, m_domain in self.domains.items():
|
||||
self.api[domain], self.acl[domain] = api_routes(m_domain)
|
||||
if domain in self.domains:
|
||||
self.api[domain], self.acl[domain] = api_routes(self.domains[domain])
|
||||
|
||||
scope_ = scope.copy()
|
||||
scope_['domains'] = self.domains
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
import time
|
||||
from datetime import datetime
|
||||
from functools import wraps
|
||||
import logging
|
||||
|
|
Loading…
Reference in New Issue