我正在尝试为GET请求的响应设置Cache-Control头。
对于OPTIONS请求,这是可行的:
PreRequestFilters.Add((httpRequest, httpResponse) =>
{
if (httpRequest.HttpMethod == "OPTIONS")
{
httpResponse.AddHeader("Cache-Control", "no-cache");
httpResponse.EndServiceStackRequest();
}
});对于GET请求,这不起作用:
ResponseFilters.Add((httpRequest, httpResponse, dto) =>
{
httpResponse.AddHeader("Cache-Control", "no-cache");
});过滤器起作用了。此外,我可以使用上面的方法将我自己的头添加到响应中。
我使用的是3.9.58。
那么,这是一个bug (在ServiceStack中还是在我的代码中),或者是由于REST和GET请求的性质而设计的?
发布于 2013-08-22 01:47:53
您不想这样做,这会终止请求:
httpResponse.EndServiceStackRequest();如果你想缩短请求的时间并阻止以后的处理,你应该使用:
httpResponse.EndRequest();但是在这种情况下,你只想添加一个头,你不想这样做。
https://stackoverflow.com/questions/18356002
复制相似问题