From 2c57d614d3ab77854b5d89625e39591c5fdf9dee Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 24 Jun 2021 13:56:22 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 7 ++++--- ahserver/processorResource.py | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 28138b2..6fd5958 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -85,7 +85,7 @@ class BaseProcessor: elif type(self.content) == type([]): self.content = json.dumps(self.content, indent=4) - self.content = unicode_escape(self.content) + # self.content = unicode_escape(self.content) self.setheaders() return Response(text=self.content,headers=self.headers) @@ -94,7 +94,8 @@ class BaseProcessor: self.content='' def setheaders(self): - self.headers['Content-Length'] = str(len(self.content)) + pass + # self.headers['Content-Length'] = str(len(self.content)) class TemplateProcessor(BaseProcessor): @classmethod @@ -172,7 +173,7 @@ class MarkdownProcessor(BaseProcessor): async def datahandle(self,request:Request): data = '' - with codecs.open(self.real_path,'r','utf-8') as f: + with codecs.open(self.real_path,'rb','utf-8') as f: data = f.read() self.content = self.urlreplace(data, request) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index f02e493..db8a658 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -242,15 +242,16 @@ class ProcessorResource(StaticResource,Url2File): return await super()._handle(request) async def html_handle(self,request,filepath): - with codecs.open(filepath,'r', 'utf-8') as f: + with open(filepath,'rb') as f: b = f.read() - b = unicode_escape(b) + utxt = b.decode('unicode_escape') + txt = b.decode('utf-8') headers = { 'Content-Type': 'text/html; utf-8', 'Accept-Ranges': 'bytes', - 'Content-Length': str(len(b)) + 'Content-Length': str(len(utxt)) } - resp = Response(text=b,headers=headers) + resp = Response(text=txt,headers=headers) return resp def isHtml(self,fn):