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 ?

share|improve this question
    
What does "does not work" mean? Is the header you set no present in the response when you examine it client-side? Is the header still present but the cached value is being used? – Ray Nicholus Aug 21 '13 at 13:07
    
Sorry, not very clear question on my side. The first example returns the header Cache-Control: no-cache. The second (which does "not work") will return Cache-Control: private. What I want to accomplish is for the second to also return Cache-Control: no-cache. – Roger Down Aug 22 '13 at 9:31

You don't want to do this, which terminates the 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.

share|improve this answer
    
Thanks for the answer... :) Regarding the deprecated method, I don't see any .EndRequest method on the httpResponse object. Do I need to add some namespace for this ? For OPTIONS in CORS, I want to just add the header and terminate the request. Code is base on an answer you gave here [link] (stackoverflow.com/questions/13741397/servicestack-cors-feat‌​ure). Perhaps the OPTIONS code should go in the ResponseFilter.Add instead ? – Roger Down Aug 22 '13 at 9:24
    
With the CORS example the desired behavior is to respond with the OPTIONS request and send the CORS HTTP Headers and end the request - the service itself shouldn't be executed. I've just updated it to use EndRequest() which is an extension method (just as EndServiceStackRequest was) in ServiceStack namespace. – mythz Aug 22 '13 at 15:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.