From 391287e3536437a40c2f04ed5b38e97b3ed65013 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 16 Dec 2025 12:00:07 +0800 Subject: [PATCH 01/15] bugfix --- ahserver/processorResource.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index f587ef2..5dcb723 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -193,7 +193,11 @@ class ProcessorResource(StaticResource,Url2File): if self._prepath != '': self._prepath = '/' + self._prepath - self._preurl = f'{self._scheme}://{self._host}:{self._port}{self._prepath}' + portp = f':{self._port}' + if self._port in [ 80, 443 ]: + portp = '' + self._preurl = f'{self._scheme}://{self._host}{portp}{self._prepath}' + request['base_url'] = self._preurl # print(f'{request.path=}, {self._preurl=}') From 803c0f5112646a4907df4a0633046723ac7eba34 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 14:54:03 +0800 Subject: [PATCH 02/15] bugfix --- ahserver/configuredServer.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index 0e01307..44a68d2 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -22,6 +22,15 @@ from .filestorage import TmpFileRecord from .loadplugins import load_plugins from .real_ip import real_ip_middleware +startup_coros = [] +cleanup_coros = [] + +def add_startup(coro): + startup_coros.append(coro) + +def add_cleanup(coro): + cleanup_coros.append(coro) + class AHApp(web.Application): def __init__(self, *args, **kw): if not kw.get('client_max_size'): @@ -30,7 +39,9 @@ class AHApp(web.Application): super().__init__(*args, **kw) self.user_data = DictObject() self.middlewares.insert(0, real_ip_middleware()) - + [ self.on_startup.append(c) for c in startup_coros ] + [ self.on_cleanup.append(c) for c in cleanup_coros ] + def set_data(self, k, v): self.user_data[k] = v From 5f8aca99607d2d00db548e4e69ca76fa43fe2a50 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 15:02:09 +0800 Subject: [PATCH 03/15] bugfix --- ahserver/configuredServer.py | 4 ++-- setup.cfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index 44a68d2..ff90e7f 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -39,8 +39,6 @@ class AHApp(web.Application): super().__init__(*args, **kw) self.user_data = DictObject() self.middlewares.insert(0, real_ip_middleware()) - [ self.on_startup.append(c) for c in startup_coros ] - [ self.on_cleanup.append(c) for c in cleanup_coros ] def set_data(self, k, v): self.user_data[k] = v @@ -117,6 +115,8 @@ class ConfiguredServer: if platform != 'win32': reuse_port = True print('reuse_port=', reuse_port) + [ self.app.on_startup.append(c) for c in startup_coros ] + [ self.app.on_cleanup.append(c) for c in cleanup_coros ] web.run_app(self.build_app(),host=config.website.host or '0.0.0.0', port=port, reuse_port=reuse_port, diff --git a/setup.cfg b/setup.cfg index f5c4bb6..54eaab1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.0.15 +version = 1.1.0 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com From a0c05d58f43550ce7d09c619282156b07366a696 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 16:16:36 +0800 Subject: [PATCH 04/15] bugfix --- ahserver/auth_api.py | 4 ++-- ahserver/processorResource.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index 168c732..351e568 100644 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -143,8 +143,8 @@ class AuthAPI: app.middlewares.append(self.checkAuth) @web.middleware - async def checkAuth(self,request,handler): - info(f'checkAuth() called ... {request.path=}') + async def checkAuth(self,request, handler): + info(f'checkAuth() called ... {request.path=}, {request.method}, {type(handler}') t1 = time.time() path = request.path userinfo = await get_session_userinfo(request) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 5dcb723..ce265f3 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -355,7 +355,7 @@ class ProcessorResource(StaticResource,Url2File): if not config.website.allowListFolder: error('%s:not found' % str(request.url)) raise HTTPNotFound - # print(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') + debug(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') return await super()._handle(request) def gethost(self, request): From cdc5aecd907e9fa23ca39069eb2a9d198cdb6d96 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 16:20:47 +0800 Subject: [PATCH 05/15] bugfix --- ahserver/processorResource.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index ce265f3..d604b46 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -355,8 +355,10 @@ class ProcessorResource(StaticResource,Url2File): if not config.website.allowListFolder: error('%s:not found' % str(request.url)) raise HTTPNotFound - debug(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') - return await super()._handle(request) + if os.path.exists(self.request_filename): + debug(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') + return await super()._handle(request) + raise Exception(f'{str(request.url)=} invalid paht') def gethost(self, request): host = request.headers.get('X-Forwarded-Host') From d18358386c3509949f000e244b464811b114693d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 16:25:03 +0800 Subject: [PATCH 06/15] bugfix --- ahserver/auth_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index 351e568..4c0664c 100644 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -144,7 +144,7 @@ class AuthAPI: @web.middleware async def checkAuth(self,request, handler): - info(f'checkAuth() called ... {request.path=}, {request.method}, {type(handler}') + info(f'checkAuth() called ... {request.path=}, {request.method}, {type(handler)}') t1 = time.time() path = request.path userinfo = await get_session_userinfo(request) From 9f4907d7581aa2c5bf407c637330e8408ceb9d54 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 17:14:08 +0800 Subject: [PATCH 07/15] bugfix --- ahserver/processorResource.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index d604b46..fb242bb 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -350,15 +350,16 @@ class ProcessorResource(StaticResource,Url2File): if self.request_filename and await self.isHtml(self.request_filename): return await self.html_handle(request, self.request_filename) - if self.request_filename and os.path.isdir(self.request_filename): + if not self.request_filename: + raise Exception(f'{str(request.url)=} invalid path') + + if os.path.isdir(self.request_filename): config = getConfig() if not config.website.allowListFolder: error('%s:not found' % str(request.url)) raise HTTPNotFound - if os.path.exists(self.request_filename): - debug(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') - return await super()._handle(request) - raise Exception(f'{str(request.url)=} invalid paht') + debug(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') + return await super()._handle(request) def gethost(self, request): host = request.headers.get('X-Forwarded-Host') From 45e6719f69ef08eebfe000abf75d3c2d5a930172 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Dec 2025 18:00:56 +0800 Subject: [PATCH 08/15] bugfix --- ahserver/processorResource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index fb242bb..cdebb13 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -188,7 +188,7 @@ class ProcessorResource(StaticResource,Url2File): port = 443 self._host = request.headers.get('X-Forwarded-Host', host) - self._port = request.headers.get('X-Forwarded-Port', port) + self._port = int(request.headers.get('X-Forwarded-Port', port)) self._prepath = request.headers.get('X-Forwarded-Prepath', '') if self._prepath != '': self._prepath = '/' + self._prepath From 5700082e64cda448b5466bf2756f13ac5e57b1df Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 19 Dec 2025 14:19:47 +0800 Subject: [PATCH 09/15] bugfix --- ahserver/processorResource.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index cdebb13..ce4894e 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -245,7 +245,10 @@ class ProcessorResource(StaticResource,Url2File): for k,v in ns.items(): if k in ['_webbricks_', '_is_mobile', '_width', '_height', 'page', 'rows' ]: if isinstance(v, str): - v = int(v) + try: + v = int(v) + except Exception as e: + exception(f'{int({v}) error, {e}') dic[k] = v return dic if request.method == 'POST': @@ -343,6 +346,7 @@ class ProcessorResource(StaticResource,Url2File): config = getConfig() request['port'] = config.website.port processor = self.url2processor(request, str(request.url), self.request_filename) + client = request['client_ip') if processor: ret = await processor.handle(request) return ret @@ -351,7 +355,7 @@ class ProcessorResource(StaticResource,Url2File): return await self.html_handle(request, self.request_filename) if not self.request_filename: - raise Exception(f'{str(request.url)=} invalid path') + raise Exception(f'{str(request.url)=} invalid path remote({client_ip})') if os.path.isdir(self.request_filename): config = getConfig() From 7b26fc47ca4c1d233aa69091f8fb8602ac814d5a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 19 Dec 2025 14:22:06 +0800 Subject: [PATCH 10/15] bugfix --- ahserver/processorResource.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index ce4894e..48c6080 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -346,7 +346,6 @@ class ProcessorResource(StaticResource,Url2File): config = getConfig() request['port'] = config.website.port processor = self.url2processor(request, str(request.url), self.request_filename) - client = request['client_ip') if processor: ret = await processor.handle(request) return ret @@ -355,7 +354,7 @@ class ProcessorResource(StaticResource,Url2File): return await self.html_handle(request, self.request_filename) if not self.request_filename: - raise Exception(f'{str(request.url)=} invalid path remote({client_ip})') + raise Exception(f'{str(request.url)=} invalid path') if os.path.isdir(self.request_filename): config = getConfig() From 534ea845c31b11379033356b5844390973b2dd11 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 19 Dec 2025 14:23:22 +0800 Subject: [PATCH 11/15] bugfix --- ahserver/processorResource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 48c6080..10b7481 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -248,7 +248,7 @@ class ProcessorResource(StaticResource,Url2File): try: v = int(v) except Exception as e: - exception(f'{int({v}) error, {e}') + exception(f'int({v}) error, {e}') dic[k] = v return dic if request.method == 'POST': From 523d05d5b1893c9d91ace1838bf8726e5feb3f37 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 22 Dec 2025 13:33:53 +0800 Subject: [PATCH 12/15] bugfix --- ahserver/globalEnv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 1684d67..0e77de8 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -54,7 +54,7 @@ from appPublic.httpclient import HttpClient from appPublic.log import debug, exception from appPublic.streamhttpclient import StreamHttpClient -from sqlor.dbpools import DBPools +from sqlor.dbpools import DBPools, get_sor_context from sqlor.filter import DBFilter, default_filterjson from aiohttp.web import StreamResponse @@ -322,6 +322,7 @@ def initEnv(): g.str_tmpl_render = string_template_render g.downloadfile2url = downloadfile2url g.background_reco = background_reco + g.get_sor_context = get_sor_context def set_builtins(): all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] From 5c7450dd5499678da77f60a583ac6f5dce463aa7 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 22 Dec 2025 17:33:02 +0800 Subject: [PATCH 13/15] bugfix --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 54eaab1..5d712af 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = ahserver -version = 1.1.0 +version = 1.1.1 description = A application server base on aiohttp author = yu moqing author_email = yumoqing@gmail.com From 1c79592bb75637b0fca6e6d3ad186211679f82a7 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 25 Dec 2025 18:02:12 +0800 Subject: [PATCH 14/15] bugfix --- ahserver/globalEnv.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 0e77de8..42addbc 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -24,6 +24,8 @@ from aiohttp.web import ( HTTPInternalServerError, HTTPBadGateway, HTTPServiceUnavailable + json_response, + Response ) from traceback import format_exc from functools import partial @@ -323,6 +325,8 @@ def initEnv(): g.downloadfile2url = downloadfile2url g.background_reco = background_reco g.get_sor_context = get_sor_context + g.json_response = json_response + g.Response = Response def set_builtins(): all_builtins = [ i for i in dir(builtins) if not i.startswith('_')] From b39f0e1f32e3f899537dff4851f6814adf63df92 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 25 Dec 2025 18:12:19 +0800 Subject: [PATCH 15/15] bugfix --- ahserver/globalEnv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ahserver/globalEnv.py b/ahserver/globalEnv.py index 42addbc..f326420 100644 --- a/ahserver/globalEnv.py +++ b/ahserver/globalEnv.py @@ -23,7 +23,7 @@ from aiohttp.web import ( HTTPTooManyRequests, HTTPInternalServerError, HTTPBadGateway, - HTTPServiceUnavailable + HTTPServiceUnavailable, json_response, Response )