mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-05-13 11:02:18 -04:00
Cleanup of lazy loading code. Made some DTOs use init rather than set to keep it clean.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user