From 0d81302386775422bb88dc314fc2e6cea613a011 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 17 May 2022 16:51:39 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 4 ++-- ahserver/p2p_middleware.py | 39 +++++++++++++++++++++++++++++++++++ ahserver/processorResource.py | 9 -------- 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 ahserver/p2p_middleware.py diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 5674c20..2359185 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -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): diff --git a/ahserver/p2p_middleware.py b/ahserver/p2p_middleware.py new file mode 100644 index 0000000..d245d46 --- /dev/null +++ b/ahserver/p2p_middleware.py @@ -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 + diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 1633bf3..5f6d515 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -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)