def _insert_footer(self, response): if not isinstance(response, FileResponse) or not self.tail_snippet: return response filepath = response._path ct, encoding = mimetypes.guess_type(str(response._path)) if ct != 'text/html': return response with filepath.open('rb') as f: body = f.read() + self.tail_snippet resp = Response(body=body, content_type='text/html') resp.last_modified = filepath.stat().st_mtime return resp