def handle_request(self, request, write_response):
if self.is_static(request) is True:
path = self.config.get('static_path')+str(request.url.path, encoding="utf-8")
path = os.path.abspath(path)
log.info("Static file read path {} ".format(path))
context = await read_file(path)
file_type = str(request.url.path, encoding="utf-8").split('.')[-1]
resp = Response(body=context, version='1.1',
content_type=TYPE_MAP.get(file_type, "text/plain"))
write_response(resp)
for hooker in self.hook.after_request:
request = hooker(request)
if isawaitable(request):
request = await request
handle = self.router.get(request=request)
if handle is None:
write_response(self.abort_404("Not found method"))
return
response = handle(request)
if isawaitable(response):
response = await response
for hooker in self.hook.before_response:
response = hooker(response)
if isawaitable(response):
response = await response
write_response(response)
评论列表
文章目录