def serve_file( file_name: str, content: bytes, default_content_type="text/plain; charset=utf-8", ) -> Response: """Construct and cache a Response from a static file.""" content_type, _ = mimetypes.guess_type(file_name) resp = Response() resp.direct_passthrough = True resp.data = content if content_type is not None: resp.headers["Content-Type"] = content_type else: resp.headers["Content-Type"] = default_content_type resp.freeze() return resp
def serve_spec( site: str, target: EndpointTarget, url: str, content_type: str, serializer: Callable[[Dict[str, Any]], str], ) -> Response: data = generate_data(target=target) data.setdefault("servers", []) add_once( data["servers"], { "url": url, "description": f"Site: {site}", }, ) response = Response(status=200) response.data = serializer(data) response.content_type = content_type response.freeze() return response