I am trying to set the Cache-Control header on the response for GET request.
This works, with OPTIONS requests:
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");
});
The filters are working... Also I am able to add my own headers to the response using the above method.
I am using 3.9.58.
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 ?
You don't want to do this, which terminates the request:
Which is also deprecated, If you want to short-circuit the request and prevent future processing you should use:
But in this situation you just want to add a header, you don't want to do this.