Install Cache-Control: no-cache in GET requests

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

This works with OPTIONS queries:

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

This does not work with GET requests:

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

Filters work ... I can also add my own headers to the response using the above method.

I am using 3.9.58.

So, is this a mistake (in ServiceStack or in my code), or is it by design due to the nature of the REST and GET requests?

+1
source share
1 answer

You do not want to do this, which completes the request:

httpResponse.EndServiceStackRequest();

which is also out of date. 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 title, you don't want to do this.

0

All Articles