Cleanup of lazy loading code. Made some DTOs use init rather than set to keep it clean.
This commit is contained in:
parent
33515ad865
commit
af35d8aad5
18 changed files with 103 additions and 68 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Text.Json;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using API.Helpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
@ -18,6 +19,23 @@ namespace API.Extensions
|
|||
response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader, options));
|
||||
response.Headers.Add("Access-Control-Expose-Headers", "Pagination");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates SHA1 hash for a byte[] and sets as ETag. Ensures Cache-Control: private header is added.
|
||||
/// </summary>
|
||||
/// <param name="response"></param>
|
||||
/// <param name="content"></param>
|
||||
public static void AddCacheHeader(this HttpResponse response, byte[] content)
|
||||
{
|
||||
// Calculates SHA1 Hash for byte[]
|
||||
if (content != null && content.Length > 0)
|
||||
{
|
||||
using var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
|
||||
response.Headers.Add("ETag", string.Concat(sha1.ComputeHash(content).Select(x => x.ToString("X2"))));
|
||||
}
|
||||
|
||||
response.Headers.Add("Cache-Control", "private");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue