简体   繁体   English

如果条件不满足,则“短路”YARP RequestTransform 并返回自定义响应

[英]"Short-circuit" YARP RequestTransform if condition is not met and return custom response

I am having issues figuring out how to stop a YARP request early and return a custom response if a certain condition is not met inside a request transform.如果在请求转换中不满足某个条件,我在弄清楚如何提前停止 YARP 请求并返回自定义响应时遇到问题。

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

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

        [...]
});

I have tried simply setting transformContext.HttpContext.Response.Status to a non-success status code as you would do for middleware, however this does not seem to work, and I have not been able to find another solution to this issue.我已经尝试像对中间件所做的那样简单地将 transformContext.HttpContext.Response.Status 设置为非成功状态代码,但这似乎不起作用,而且我无法找到解决此问题的另一种解决方案。

Perhaps you should use a middleware.也许您应该使用中间件。 If you take a look at the documentation, you can intercept using a middleware.如果您查看文档,您可以使用中间件进行拦截。

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

if you return before next() , the proxy does not get called.如果您在next()之前返回,则不会调用代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM