【问题标题】:"Short-circuit" YARP RequestTransform if condition is not met and return custom response如果条件不满足,则“短路”YARP RequestTransform 并返回自定义响应
【发布时间】:2021-12-06 03:49:32
【问题描述】:

如果在请求转换中不满足特定条件,我无法弄清楚如何提前停止 YARP 请求并返回自定义响应。

builderContext.AddRequestTransform(async transformContext =>
{
        [...]

        if (!condition)
        {
                // TODO: stop request and return response
        }

        [...]
});

我尝试像对中间件所做的那样简单地将 transformContext.HttpContext.Response.Status 设置为非成功状态代码,但这似乎不起作用,而且我无法找到解决此问题的其他方法.

【问题讨论】:

    标签: c# asp.net asp.net-core asp.net-core-3.1 yarp


    【解决方案1】:

    也许您应该使用中间件。如果您查看文档,您可以使用中间件进行拦截。

    https://microsoft.github.io/reverse-proxy/articles/middleware.html#adding-middleware

    如果您在next() 之前返回,则不会调用代理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多