Describe the bug
I'd like to modify the response headers to enable caching. Currently, all responses contain Cache-Control: no-store, no-cache, must-revalidate. I would like to have Cache-Control: public to enable caching.
To Reproduce
Steps to reproduce the behavior:
```c#
[WebApiHandler(HttpVerbs.Get, "/api/symbols/")]
public async Task
{
try
{
[...]
context.Response.Headers.Add("Cache-Control: public");
return context.JsonResponse(myData);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
return context.JsonExceptionResponse(ex);
}
}
``
**Expected behavior**
Browsers response header showsCache-Control: public`
Actual behavior
Browsers response header shows Cache-Control: no-store, no-cache, must-revalidate
Desktop:
Yes, the current implementation is always calling NoCache before the WebAPI method.
I'm going to change the logic to set the NoCache after the WebAPI method, and only if there is no Cache-Control header yet.
Good catch!
Hi @felixerdy, I was thinking on this approach: https://github.com/unosquare/embedio/pull/184
Basically, you need to add to your controller the following method:
public override void SetDefaultHeaders(HttpListenerContext context)
And A) Add your default headers (like public cache) or B) Set nothing and allow setting cache per Web API Method.
Let me know what you think.
馃憤 Yes I think that would be a good way
Please use the new version 1.6.0 (https://www.nuget.org/packages/EmbedIO/1.16.0)
Don't forget star this project 馃憤
Works like a charme 馃
Thanks for your work!
@geoperez may I ask you to include this option also in WebApiController too?
Hello, the method SetDefaultHeaders is for WebApiController, just override it