Merge branch 'main' of git.opencomputing.cn:yumoqing/ahserver
This commit is contained in:
commit
e56b6ec702
@ -143,8 +143,8 @@ class AuthAPI:
|
|||||||
app.middlewares.append(self.checkAuth)
|
app.middlewares.append(self.checkAuth)
|
||||||
|
|
||||||
@web.middleware
|
@web.middleware
|
||||||
async def checkAuth(self,request,handler):
|
async def checkAuth(self,request, handler):
|
||||||
info(f'checkAuth() called ... {request.path=}')
|
info(f'checkAuth() called ... {request.path=}, {request.method}, {type(handler)}')
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
path = request.path
|
path = request.path
|
||||||
userinfo = await get_session_userinfo(request)
|
userinfo = await get_session_userinfo(request)
|
||||||
|
|||||||
@ -22,6 +22,15 @@ from .filestorage import TmpFileRecord
|
|||||||
from .loadplugins import load_plugins
|
from .loadplugins import load_plugins
|
||||||
from .real_ip import real_ip_middleware
|
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):
|
class AHApp(web.Application):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
if not kw.get('client_max_size'):
|
if not kw.get('client_max_size'):
|
||||||
@ -106,6 +115,8 @@ class ConfiguredServer:
|
|||||||
if platform != 'win32':
|
if platform != 'win32':
|
||||||
reuse_port = True
|
reuse_port = True
|
||||||
print('reuse_port=', reuse_port)
|
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',
|
web.run_app(self.build_app(),host=config.website.host or '0.0.0.0',
|
||||||
port=port,
|
port=port,
|
||||||
reuse_port=reuse_port,
|
reuse_port=reuse_port,
|
||||||
|
|||||||
@ -23,7 +23,9 @@ from aiohttp.web import (
|
|||||||
HTTPTooManyRequests,
|
HTTPTooManyRequests,
|
||||||
HTTPInternalServerError,
|
HTTPInternalServerError,
|
||||||
HTTPBadGateway,
|
HTTPBadGateway,
|
||||||
HTTPServiceUnavailable
|
HTTPServiceUnavailable,
|
||||||
|
json_response,
|
||||||
|
Response
|
||||||
)
|
)
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -54,7 +56,7 @@ from appPublic.httpclient import HttpClient
|
|||||||
from appPublic.log import debug, exception
|
from appPublic.log import debug, exception
|
||||||
from appPublic.streamhttpclient import StreamHttpClient
|
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 sqlor.filter import DBFilter, default_filterjson
|
||||||
from aiohttp.web import StreamResponse
|
from aiohttp.web import StreamResponse
|
||||||
|
|
||||||
@ -324,6 +326,9 @@ def initEnv():
|
|||||||
g.str_tmpl_render = string_template_render
|
g.str_tmpl_render = string_template_render
|
||||||
g.downloadfile2url = downloadfile2url
|
g.downloadfile2url = downloadfile2url
|
||||||
g.background_reco = background_reco
|
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):
|
def i18n(request, *args, **kw):
|
||||||
env = request._rns_ns
|
env = request._rns_ns
|
||||||
|
|||||||
@ -188,12 +188,16 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
port = 443
|
port = 443
|
||||||
|
|
||||||
self._host = request.headers.get('X-Forwarded-Host', host)
|
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', '')
|
self._prepath = request.headers.get('X-Forwarded-Prepath', '')
|
||||||
if self._prepath != '':
|
if self._prepath != '':
|
||||||
self._prepath = '/' + 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=}')
|
# print(f'{request.path=}, {self._preurl=}')
|
||||||
|
|
||||||
|
|
||||||
@ -241,7 +245,10 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
for k,v in ns.items():
|
for k,v in ns.items():
|
||||||
if k in ['_webbricks_', '_is_mobile', '_width', '_height', 'page', 'rows' ]:
|
if k in ['_webbricks_', '_is_mobile', '_width', '_height', 'page', 'rows' ]:
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
v = int(v)
|
try:
|
||||||
|
v = int(v)
|
||||||
|
except Exception as e:
|
||||||
|
exception(f'int({v}) error, {e}')
|
||||||
dic[k] = v
|
dic[k] = v
|
||||||
return dic
|
return dic
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@ -346,12 +353,15 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
if self.request_filename and await self.isHtml(self.request_filename):
|
if self.request_filename and await self.isHtml(self.request_filename):
|
||||||
return await self.html_handle(request, 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()
|
config = getConfig()
|
||||||
if not config.website.allowListFolder:
|
if not config.website.allowListFolder:
|
||||||
error('%s:not found' % str(request.url))
|
error('%s:not found' % str(request.url))
|
||||||
raise HTTPNotFound
|
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)
|
return await super()._handle(request)
|
||||||
|
|
||||||
def gethost(self, request):
|
def gethost(self, request):
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# setup.cfg
|
# setup.cfg
|
||||||
[metadata]
|
[metadata]
|
||||||
name = ahserver
|
name = ahserver
|
||||||
version = 1.0.15
|
version = 1.1.1
|
||||||
description = A application server base on aiohttp
|
description = A application server base on aiohttp
|
||||||
author = yu moqing
|
author = yu moqing
|
||||||
author_email = yumoqing@gmail.com
|
author_email = yumoqing@gmail.com
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user