ServiceStack的EndRequest方法中可选的“skipHeaders”参数的用途是什么?

时间:2014-09-03 16:53:12

标签: servicestack

1)ServiceStack的 EndRequest 方法中的可选 skipHeaders 参数的用途是什么,如下所示?或者换句话说,当 skipHeaders true false 时会发生什么?

    this.UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
         res.Write("Error: {0}: {1}".Fmt(ex.GetType().Name, ex.Message));
         res.EndRequest(skipHeaders: true);
    });

2)下面显示的用法是否正确(我想拒绝来自反向代理的请求)?

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
    public sealed class DenyRequestFromReverseProxyAttribute : RequestFilterAttribute
    {
        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (req.Headers.AllKeys.Contains("X-Forwarded-For"))
            {
                res.StatusCode = (int)HttpStatusCode.Forbidden;
                res.Write("Forbidden - For internal use only.");
                res.EndRequest(skipHeaders: true);
            }
        }
    }

1 个答案:

答案 0 :(得分:3)

确定是否编写Config.GlobalResponseHeaders HTTP标头。如果您已经写入了想要skipHeaders:true的回复流。