add caching headers
This commit is contained in:
parent
322dd01ee0
commit
a98a61e040
1 changed files with 8 additions and 3 deletions
|
@ -31,13 +31,18 @@ public class MediaController(IMediaModule mediaModule) : ControllerBase
|
|||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize]
|
||||
public async Task GetMedia(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var res = await mediaModule.PostQuery(new LoadFileQuery(id), cancellationToken);
|
||||
|
||||
// Set cache headers
|
||||
HttpContext.Response.Headers.CacheControl = "public,max-age=31536000"; // Cache for 1 year
|
||||
HttpContext.Response.Headers.Expires = DateTime.UtcNow.AddYears(1).ToString("R");
|
||||
|
||||
// If you want to support cache validation
|
||||
HttpContext.Response.Headers.ETag = $"\"{id}\""; // Using the file ID as ETag
|
||||
|
||||
HttpContext.Response.ContentType = res.Type;
|
||||
HttpContext.Response.ContentLength = res.Size;
|
||||
await res.Data.CopyToAsync(HttpContext.Response.Body, cancellationToken);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue