Пример #1
0
    async def __call__(self, receive: Receive, send: Send) -> None:
        if self.check_directory is not None:
            await self.check_directory_configured_correctly()

        try:
            stat_result = await aio_stat(self.path)
        except FileNotFoundError:
            response = PlainTextResponse("Not Found", status_code=404)  # type: Response
        else:
            mode = stat_result.st_mode
            if not stat.S_ISREG(mode):
                response = PlainTextResponse("Not Found", status_code=404)
            else:
                stat_headers = FileResponse.get_stat_headers(stat_result)
                if self.is_not_modified(stat_headers):
                    response = self.not_modified_response(stat_headers)
                else:
                    response = FileResponse(
                        self.path, stat_result=stat_result, method=self.scope["method"]
                    )

        await response(receive, send)