Set Cache-Control:no-cache对GET请求 [英] Set Cache-Control: no-cache on GET requests

查看:505
本文介绍了Set Cache-Control:no-cache对GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在GET请求的响应中设置Cache-Control标头。

I am trying to set the Cache-Control header on the response for GET request.

这样做与OPTIONS请求:

This works, with OPTIONS requests:

PreRequestFilters.Add((httpRequest, httpResponse) =>
{
   if (httpRequest.HttpMethod == "OPTIONS")
   {
      httpResponse.AddHeader("Cache-Control", "no-cache");
      httpResponse.EndServiceStackRequest();
   }
});

这不适用于GET请求:

This does not work, with GET requests:

ResponseFilters.Add((httpRequest, httpResponse, dto) =>
{
   httpResponse.AddHeader("Cache-Control", "no-cache");
});

过滤器正在工作...也可以使用上面的方法。

The filters are working... Also I am able to add my own headers to the response using the above method.

我使用的是3.9.58。

I am using 3.9.58.

在我的代码中),或者是由于REST和GET请求的性质而设计的?

So, is this a bug (in ServiceStack or in my code), or is this by design because of the nature of REST and GET request ?

推荐答案

为此,它终止请求:

httpResponse.EndServiceStackRequest();

这也是不推荐使用的,如果你想短接请求并阻止未来的处理,你应该使用:

Which is also deprecated, If you want to short-circuit the request and prevent future processing you should use:

httpResponse.EndRequest();

但在这种情况下,你只是想添加一个头,你不想这样做。

But in this situation you just want to add a header, you don't want to do this.

这篇关于Set Cache-Control:no-cache对GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆