1
1)什麼是可選的skipHeaders參數在ServiceStack的EndRequest方法的目的是什麼?或者換句話說,什麼時候發生了什麼skipHeaders是true或false?ServiceStack的EndRequest方法中可選「skipHeaders」參數的用途是什麼?
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);
}
}
}