def serve_file(file_path): response = Response() fs = os.stat(file_path) mimetype = mimetypes.guess_type(file_path) response.set_header("Content-length", str(fs.st_size)) if file_path.endswith('.manifest'): response.set_header("Content-type", 'text/cache-manifest') response.set_header("Expires", 'access') else: response.set_header("Content-type", mimetype[0] or 'text/plain') response.set_header("Last-Modified", date_time_string(fs.st_mtime)) response.content = open(file_path, 'rb') response.type = "file" return response
def serve_file(file_path): response = Response() size = os.path.getsize(file_path) mimetype = mimetypes.guess_type(file_path) response.set_header("Content-type", mimetype[0] or 'text/plain') response.set_header("Content-length", str(size)) response.set_header("Cache-Control", 'public, max-age=22222222') response.content = open(file_path, 'rb') response.type = "file" return response