Compute file server etag with MD5 and always include ModifiedOn
This commit is contained in:
@ -137,15 +137,15 @@ namespace Oqtane.Pages
|
||||
string downloadName = file.Name;
|
||||
string filepath = _files.GetFilePath(file);
|
||||
|
||||
var etagInput = $"{file.ModifiedOn.Ticks}:{file.Size}";
|
||||
|
||||
if (Request.QueryString.HasValue)
|
||||
{
|
||||
etag = Utilities.GenerateSimpleHash(Request.QueryString.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
etag = Convert.ToString(file.ModifiedOn.Ticks ^ file.Size, 16);
|
||||
etagInput += $":{Request.QueryString.Value}";
|
||||
}
|
||||
|
||||
etag = Utilities.GenerateHashMD5(etagInput);
|
||||
|
||||
var header = "";
|
||||
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using File = Oqtane.Models.File;
|
||||
@ -619,6 +620,13 @@ namespace Oqtane.Shared
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateHashMD5(string input)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(input);
|
||||
var hashBytes = MD5.HashData(bytes);
|
||||
return Convert.ToHexString(hashBytes);
|
||||
}
|
||||
|
||||
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
||||
public static string ContentUrl(Alias alias, int fileId)
|
||||
{
|
||||
|
Reference in New Issue
Block a user