部署在openfaas中的函数如何向调用方返回不同的HTTP状态代码?就像4xx密码。
根据文档,看门狗将处理http状态200或5xx的stdout或stderr。
有没有办法改变像400,409等的状态?我使用的是faas-cli下载的csharp模板
发布于 2018-11-27 02:32:36
你不能,就像这里所说的,https://github.com/openfaas/faas-netes/issues/147
建议的解决方案是返回带有状态代码的有效负载,并在接收端解析有效负载。
发布于 2019-10-10 02:25:22
即使在system.exit(1)或抛出异常时,默认python模板似乎返回200。我假设其他较旧的模板的行为类似,这是对经典的看门狗的期望。
但是,如果您使用支持运行新的看门狗,我认为它可以返回非200码,如400,404等。的语言模板,您可以使用faas-cli下载这些模板,它们来自openfaas-孵化器项目和社区。
我刚刚证实,使用python3-http语言/模板来自openfaas-孵化器,和从远距凸轮中获取,非200代码可以返回像400,404等。
这将列出可用的模板:
faas-cli template store list要安装我测试过的csharp模板:
faas-cli template store pull distantcam/csharp-httprequest可以像这样轻松地修改的OOTB处理程序,以返回400:
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Threading.Tasks;
namespace Function
{
public class FunctionHandler
{
public async Task<(int, string)> Handle(HttpRequest request)
{
var reader = new StreamReader(request.Body);
var input = await reader.ReadToEndAsync();
return (400, $"Hello! Your input was {input}");
}
}
}发布于 2022-05-30 15:59:53
在对如何在python中使用它进行了大量研究之后,不要使用临时模板,您应该使用python-烧瓶模板。就像一种魅力。
https://stackoverflow.com/questions/53453517
复制相似问题