From 36c86520f017aa0a12fa4175a13306e505ee1e9b Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 5 Aug 2023 16:41:27 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 491df42..5ef135b 100755 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -90,17 +90,26 @@ class BaseProcessor(AppLogger): async def handle(self,request): await self.execute(request) + jsonflg = False if self.retResponse is not None: self.set_response_headers(self.retResponse) return self.retResponse elif type(self.content) == type({}) : - self.content = json.dumps(self.content, - indent=4) + self.content = json.dumps(self.content, indent=4) + jsonflg = True elif type(self.content) == type([]): - self.content = json.dumps(self.content, - indent=4) + self.content = json.dumps(self.content, indent=4) + jsonflg = True + else: + try: + json.loads(self.content) + jsonflg = True + except: + pass - self.headers['Content-Type'] = "application/json; utf-8" + if jsonflg: + self.headers['Content-Type'] = "application/json; utf-8" + self.headers['Access-Control-Expose-Headers'] = 'Set-Cookie' resp = Response(text=self.content,headers=self.headers) self.set_response_headers(resp)