Compare commits

..

2 Commits

Author SHA1 Message Date
yumoqing
21143f0138 bugfix 2024-02-18 18:23:40 +08:00
yumoqing
9cd3bfe539 bugfix 2024-02-18 18:20:52 +08:00
3 changed files with 29 additions and 6 deletions

View File

@ -136,7 +136,7 @@ class TemplateProcessor(BaseProcessor):
url = self.resource.entireUrl(request, path)
ns = self.run_ns
te = self.run_ns['tmpl_engine']
print(f'{url=}, {path=}')
# print(f'{url=}, {path=}')
# return await te.render(url,**ns)
return await te.render(path,**ns)
@ -155,7 +155,7 @@ class TemplateProcessor(BaseProcessor):
class BricksUIProcessor(TemplateProcessor):
@classmethod
def isMe(self,name):
print(f'{name=} is a bui')
# print(f'{name=} is a bui')
return name=='bui'
async def datahandle(self, request):
@ -215,7 +215,7 @@ class MarkdownProcessor(BaseProcessor):
mdtxt)
def getProcessor(name):
print(f'getProcessor({name})')
# print(f'getProcessor({name})')
return _getProcessor(BaseProcessor, name)
def _getProcessor(kclass,name):

View File

@ -18,7 +18,7 @@ class TmplLoader(BaseLoader, TmplUrl2File):
coding = config.website.coding
fp = self.url2file(template)
print(f'{template=} can not transfer to filename')
# print(f'{template=} can not transfer to filename')
if not os.path.isfile(fp):
raise TemplateNotFound(template)
mtime = os.path.getmtime(fp)

View File

@ -167,6 +167,27 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
# print(f'getPostData():{ns=}')
return ns
def parse_request(self, request):
"""
get real schema, host, port, prepath
and save it to self._{attr}
"""
self._scheme = request.scheme
self._scheme = request.headers.get('X-Forwarded-Scheme',request.scheme)
k = request.host.split(':')
host = k[0]
port = 80
if len(k) == 2:
port = int(k[1])
elif self._scheme.lower() == 'https':
port = 443
self._host = request.headers.get('X-Forwarded-Host', host)
self._port = request.headers.get('X-Forwarded-Port', port)
self._prepath = request.headers.get('X-Forwarded-Prepath', '')
async def _handle(self,request:Request) -> StreamResponse:
clientkeys = {
"iPhone":"iphone",
@ -231,6 +252,8 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
async def get_user():
return await auth.get_auth(request)
self.parse_request(request)
self.y_env.i18n = serveri18n
self.y_env.file_realpath = file_realpath
self.y_env.redirect = redirect
@ -301,7 +324,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
if not config.website.allowListFolder:
self.error('%s:not found' % str(request.url))
raise HTTPNotFound
print(f'{self.request_filename=}, {str(request.url)=} handle as a normal file')
# print(f'{self.request_filename=}, {str(request.url)=} handle as a normal file')
return await super()._handle(request)
def gethost(self, request):
@ -393,7 +416,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
async def path_call(self, request, path, params={}):
url = self.entireUrl(request, path)
print(f'{path=}, after entireUrl(), {url=}')
# print(f'{path=}, after entireUrl(), {url=}')
fpath = self.url2file(url)
processor = self.url2processor(request, url, fpath)
new_request = request.clone(rel_url=url)