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 downloadName = file.Name;
|
||||||
string filepath = _files.GetFilePath(file);
|
string filepath = _files.GetFilePath(file);
|
||||||
|
|
||||||
|
var etagInput = $"{file.ModifiedOn.Ticks}:{file.Size}";
|
||||||
|
|
||||||
if (Request.QueryString.HasValue)
|
if (Request.QueryString.HasValue)
|
||||||
{
|
{
|
||||||
etag = Utilities.GenerateSimpleHash(Request.QueryString.Value);
|
etagInput += $":{Request.QueryString.Value}";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
etag = Convert.ToString(file.ModifiedOn.Ticks ^ file.Size, 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
etag = Utilities.GenerateHashMD5(etagInput);
|
||||||
|
|
||||||
var header = "";
|
var header = "";
|
||||||
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))
|
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using File = Oqtane.Models.File;
|
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)]
|
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
||||||
public static string ContentUrl(Alias alias, int fileId)
|
public static string ContentUrl(Alias alias, int fileId)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user