This commit is contained in:
yumoqing 2021-06-24 13:56:22 +08:00
parent 26b01e96ac
commit 2c57d614d3
2 changed files with 9 additions and 7 deletions

View File

@ -85,7 +85,7 @@ class BaseProcessor:
elif type(self.content) == type([]): elif type(self.content) == type([]):
self.content = json.dumps(self.content, self.content = json.dumps(self.content,
indent=4) indent=4)
self.content = unicode_escape(self.content) # self.content = unicode_escape(self.content)
self.setheaders() self.setheaders()
return Response(text=self.content,headers=self.headers) return Response(text=self.content,headers=self.headers)
@ -94,7 +94,8 @@ class BaseProcessor:
self.content='' self.content=''
def setheaders(self): def setheaders(self):
self.headers['Content-Length'] = str(len(self.content)) pass
# self.headers['Content-Length'] = str(len(self.content))
class TemplateProcessor(BaseProcessor): class TemplateProcessor(BaseProcessor):
@classmethod @classmethod
@ -172,7 +173,7 @@ class MarkdownProcessor(BaseProcessor):
async def datahandle(self,request:Request): async def datahandle(self,request:Request):
data = '' 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() data = f.read()
self.content = self.urlreplace(data, request) self.content = self.urlreplace(data, request)

View File

@ -242,15 +242,16 @@ class ProcessorResource(StaticResource,Url2File):
return await super()._handle(request) return await super()._handle(request)
async def html_handle(self,request,filepath): 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 = f.read()
b = unicode_escape(b) utxt = b.decode('unicode_escape')
txt = b.decode('utf-8')
headers = { headers = {
'Content-Type': 'text/html; utf-8', 'Content-Type': 'text/html; utf-8',
'Accept-Ranges': 'bytes', '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 return resp
def isHtml(self,fn): def isHtml(self,fn):