Embedio: Modify Response Headers to enable caching

Created on 10 Aug 2018  路  7Comments  路  Source: unosquare/embedio

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 GetSymbolsAsync(WebServer server, HttpListenerContext context)
{
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:

  • OS: Windows 10
  • Browser: Google Chrome
  • Version: 68
bug

All 7 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RyanYANG52 picture RyanYANG52  路  4Comments

Genteure picture Genteure  路  5Comments

bufferUnderrun picture bufferUnderrun  路  4Comments

SaricVr picture SaricVr  路  9Comments

Dewyer picture Dewyer  路  7Comments