bugfix
This commit is contained in:
parent
21143f0138
commit
71d6a3d528
@ -106,9 +106,11 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
|||||||
def setIndexes(self, indexes):
|
def setIndexes(self, indexes):
|
||||||
self.y_indexes = indexes
|
self.y_indexes = indexes
|
||||||
|
|
||||||
|
|
||||||
def abspath(self, request, path:str):
|
def abspath(self, request, path:str):
|
||||||
url = self.entireUrl(request, path)
|
url = self.entireUrl(request, path)
|
||||||
fname = self.url2file(url)
|
path = self.url2path(url)
|
||||||
|
fname = self.url2file(path)
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
async def getPostData(self,request: Request) -> dict:
|
async def getPostData(self,request: Request) -> dict:
|
||||||
@ -187,6 +189,9 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
|||||||
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 = request.headers.get('X-Forwarded-Port', port)
|
||||||
self._prepath = request.headers.get('X-Forwarded-Prepath', '')
|
self._prepath = request.headers.get('X-Forwarded-Prepath', '')
|
||||||
|
self._preurl = f'{self._scheme}://{self._host}:{self._port}{self._prepath}'
|
||||||
|
print(f'{request.path=}, {self._preurl=}')
|
||||||
|
|
||||||
|
|
||||||
async def _handle(self,request:Request) -> StreamResponse:
|
async def _handle(self,request:Request) -> StreamResponse:
|
||||||
clientkeys = {
|
clientkeys = {
|
||||||
@ -400,12 +405,12 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
|||||||
url.startswith('ws://') or \
|
url.startswith('ws://') or \
|
||||||
url.startswith('wss://'):
|
url.startswith('wss://'):
|
||||||
return url
|
return url
|
||||||
scheme = request.headers.get('X-Forwarded-Scheme') or request.scheme
|
scheme = self._scheme
|
||||||
port = request.headers.get('X-Forwarded-Port') or str(request['port'])
|
port = self._port
|
||||||
prepath = request.headers.get('X-Forwarded-Prepath') or ''
|
prepath = self._prepath
|
||||||
if prepath != '':
|
if prepath != '':
|
||||||
prepath = f'/{prepath}'
|
prepath = f'/{prepath}'
|
||||||
h = self.gethost(request)
|
h = self._host
|
||||||
if url.startswith('/'):
|
if url.startswith('/'):
|
||||||
return f'{scheme}://{h}:{port}{prepath}{url}'
|
return f'{scheme}://{h}:{port}{prepath}{url}'
|
||||||
path = request.path
|
path = request.path
|
||||||
@ -414,10 +419,16 @@ class ProcessorResource(AppLogger, StaticResource,Url2File):
|
|||||||
p = self.relatedurl(path,url)
|
p = self.relatedurl(path,url)
|
||||||
return f'{scheme}://{h}:{port}{prepath}{p}'
|
return f'{scheme}://{h}:{port}{prepath}{p}'
|
||||||
|
|
||||||
|
def url2path(self, url):
|
||||||
|
if url.startswith(self._prepath):
|
||||||
|
return url[len(self._prepath):]
|
||||||
|
return url
|
||||||
|
|
||||||
async def path_call(self, request, path, params={}):
|
async def path_call(self, request, path, params={}):
|
||||||
url = self.entireUrl(request, path)
|
url = self.entireUrl(request, path)
|
||||||
# print(f'{path=}, after entireUrl(), {url=}')
|
# print(f'{path=}, after entireUrl(), {url=}')
|
||||||
fpath = self.url2file(url)
|
path = self.url2path(url)
|
||||||
|
fpath = self.url2file(path)
|
||||||
processor = self.url2processor(request, url, fpath)
|
processor = self.url2processor(request, url, fpath)
|
||||||
new_request = request.clone(rel_url=url)
|
new_request = request.clone(rel_url=url)
|
||||||
# new_request.path = path
|
# new_request.path = path
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
class Url2File:
|
class Url2File:
|
||||||
def __init__(self,path:str,prefix: str,
|
def __init__(self,path:str,prefix: str,
|
||||||
indexes: list, inherit: bool=False):
|
indexes: list, inherit: bool=False):
|
||||||
self.path = path
|
self.rootpath = path
|
||||||
self.starts = prefix
|
self.starts = prefix
|
||||||
self.indexes = indexes
|
self.indexes = indexes
|
||||||
self.inherit = inherit
|
self.inherit = inherit
|
||||||
@ -31,7 +31,7 @@ class Url2File:
|
|||||||
url.startswith('ws://') or \
|
url.startswith('ws://') or \
|
||||||
url.startswith('wss://'):
|
url.startswith('wss://'):
|
||||||
paths = paths[3:]
|
paths = paths[3:]
|
||||||
f = os.path.join(self.path,*paths)
|
f = os.path.join(self.rootpath,*paths)
|
||||||
real_path = os.path.abspath(f)
|
real_path = os.path.abspath(f)
|
||||||
# print(f'{real_path=}, {url=}, {f=}')
|
# print(f'{real_path=}, {url=}, {f=}')
|
||||||
return real_path
|
return real_path
|
||||||
@ -51,11 +51,11 @@ class Url2File:
|
|||||||
return real_path
|
return real_path
|
||||||
|
|
||||||
if not os.path.isdir(os.path.dirname(real_path)):
|
if not os.path.isdir(os.path.dirname(real_path)):
|
||||||
# print(f'url2file() return None, {real_path=}, {url=},{ourl=}, {self.path=}')
|
# print(f'url2file() return None, {real_path=}, {url=},{ourl=}, {self.rootpath=}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not self.inherit:
|
if not self.inherit:
|
||||||
# print(f'url2file() return None, self.inherit is false, {url:}, {self.path=}')
|
# print(f'url2file() return None, self.inherit is false, {url:}, {self.rootpath=}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
items = url.split('/')
|
items = url.split('/')
|
||||||
@ -65,7 +65,7 @@ class Url2File:
|
|||||||
url = '/'.join(items)
|
url = '/'.join(items)
|
||||||
# print(f'{oldurl=}, {url=}')
|
# print(f'{oldurl=}, {url=}')
|
||||||
return self.url2file(url)
|
return self.url2file(url)
|
||||||
# print(f'url2file() return None finally, {items:}, {url=}, {ourl=}, {self.path=}')
|
# print(f'url2file() return None finally, {items:}, {url=}, {ourl=}, {self.rootpath=}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def relatedurl(self,url: str, name: str) -> str:
|
def relatedurl(self,url: str, name: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user