This commit is contained in:
yumoqing 2022-05-17 16:51:39 +08:00
parent 52b21ad388
commit 0d81302386
3 changed files with 41 additions and 11 deletions

View File

@ -86,8 +86,8 @@ class BaseProcessor:
elif type(self.content) == type([]):
self.content = json.dumps(self.content,
indent=4)
# self.content = unicode_escape(self.content)
self.setheaders()
self.headers['Content-Type'] = "application/json; utf-8"
return Response(text=self.content,headers=self.headers)
async def datahandle(self,request):

View File

@ -0,0 +1,39 @@
from aiohttp import web
from p2psc.pubkey_handler import PubkeyHandler
from p2psc.p2psc import P2psc
class P2pLayer
def __init__(self):
self.p2pcrypt = False
config = getConfig()
if config.website.p2pcrypt:
self.p2pcrypt = True
if not self.p2pcrypt:
return
self.handler = PubkeyHandler()
self.p2p = P2psc(self.handler, self.handler.get_myid())
@web.middleware
async def p2p_middle(self, request, handler):
if not p2pscrypr:
return await handler(request)
if request.headers.get('P2pHandShake', None):
resturen await self.p2p_handshake(request)
if request.header.get('P2pdata', None):
request = await self.p2p_decode_request(request)
resp = await handler(request)
return await self.p2p_encode_response(resp)
return handler(request)
async def p2p_handshake(self, request):
pass
async def p2p_decode_request(self, request):
pass
async def p2p_encode_response(self, response):
return response

View File

@ -182,7 +182,6 @@ class ProcessorResource(StaticResource,Url2File):
self.y_env.i18n = serveri18n
self.y_env.i18nDict = i18nDICT
self.y_env.terminalType = getClientType(request)
self.y_env.absurl = self.absUrl
self.y_env.entire_url = partial(self.entireUrl,request)
self.y_env.abspath = self.abspath
self.y_env.request2ns = getArgs
@ -316,11 +315,3 @@ class ProcessorResource(StaticResource,Url2File):
processor = self.url2processor(request, url, fpath)
return await processor.path_call(request, params=params)
def absUrl(self,request,url):
http='http://'
https='https://'
if url.startswith('https://') or url.startswith('http://') :
return url
path = request.path
new_path = self.relatedurl(path,url)
return self.entireUrl(request, new_path)