diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index 14d5d62..5b771b9 100755 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -85,16 +85,26 @@ class AuthAPI(AppLogger): @web.middleware async def checkAuth(self,request,handler): - print('checkAuth() called ..................') + self.info(f'checkAuth() called ...{request.path}') + t1 = time.time() path = request.path user = await auth.get_auth(request) is_ok = await self.checkUserPermission(user, path) + t2 = time.time() if is_ok: - return await handler(request) + try: + ret = await handler(request) + t3 = time.time() + self.info(f'timecost={user} access {path} cost {t3-t1}, ({t2-t1})') + return ret + except Exception as e: + self.info(f'timecost={user} access {path} cost {t3-t1}, ({t2-t1}), except={e}') + raise e + if user is None: - print(f'**{user=}, {path} need login**') + self.info(f'timecost={user} access need login to access {path} ({t2-t1})') raise web.HTTPUnauthorized - print(f'**{user=}, {path} forbidden**') + self.info(f'timecost={user} access {path} forbidden ({t2-t1})') raise web.HTTPForbidden() async def needAuth(self,path): diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 33e9249..52eb6bd 100755 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -165,21 +165,6 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): return ns async def _handle(self,request:Request) -> StreamResponse: - name = str(request.url) - t = TimeCost(name) - with t: - try: - x = await self._handle1(request) - except Exception as e: - self.error(f'{name}:error={e}') - print_exc() - x = e - self.info(f'{name}:time cost={t.end_time - t.begin_time}') - if not isinstance(x, StreamResponse): - return HTTPException - return x - - async def _handle1(self,request:Request) -> StreamResponse: clientkeys = { "iPhone":"iphone", "iPad":"ipad",