Merge branch 'main' of git.opencomputing.cn:yumoqing/ahserver

This commit is contained in:
yumoqing 2025-12-28 12:53:37 +08:00
commit e56b6ec702
5 changed files with 37 additions and 11 deletions

View File

@ -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)

View File

@ -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'):
@ -106,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,

View File

@ -23,7 +23,9 @@ from aiohttp.web import (
HTTPTooManyRequests,
HTTPInternalServerError,
HTTPBadGateway,
HTTPServiceUnavailable
HTTPServiceUnavailable,
json_response,
Response
)
from traceback import format_exc
from functools import partial
@ -54,7 +56,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
@ -324,6 +326,9 @@ def initEnv():
g.str_tmpl_render = string_template_render
g.downloadfile2url = downloadfile2url
g.background_reco = background_reco
g.get_sor_context = get_sor_context
g.json_response = json_response
g.Response = Response
def i18n(request, *args, **kw):
env = request._rns_ns

View File

@ -188,12 +188,16 @@ 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
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=}')
@ -241,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':
@ -346,12 +353,15 @@ 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
# 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):

View File

@ -1,7 +1,7 @@
# setup.cfg
[metadata]
name = ahserver
version = 1.0.15
version = 1.1.1
description = A application server base on aiohttp
author = yu moqing
author_email = yumoqing@gmail.com