Merge pull request #5253 from mdmontesinos/files-optimization
Files server optimization
This commit is contained in:
@ -112,7 +112,7 @@ namespace Oqtane.Pages
|
|||||||
|
|
||||||
url += Request.QueryString.Value.Substring(1);
|
url += Request.QueryString.Value.Substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectPermanent(url);
|
return RedirectPermanent(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,10 +133,29 @@ namespace Oqtane.Pages
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string etag;
|
string etag = Convert.ToString(file.ModifiedOn.Ticks ^ file.Size, 16);
|
||||||
string downloadName = file.Name;
|
string downloadName = file.Name;
|
||||||
string filepath = _files.GetFilePath(file);
|
string filepath = _files.GetFilePath(file);
|
||||||
|
|
||||||
|
var header = "";
|
||||||
|
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))
|
||||||
|
{
|
||||||
|
header = ifNoneMatch.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header.Equals(etag))
|
||||||
|
{
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
|
||||||
|
return Content(String.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(filepath))
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Read, "File Does Not Exist {FilePath}", filepath);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
|
return BrokenFile();
|
||||||
|
}
|
||||||
|
|
||||||
// evaluate any querystring parameters
|
// evaluate any querystring parameters
|
||||||
bool isRequestingImageManipulation = false;
|
bool isRequestingImageManipulation = false;
|
||||||
|
|
||||||
@ -165,34 +184,6 @@ namespace Oqtane.Pages
|
|||||||
isRequestingImageManipulation = true;
|
isRequestingImageManipulation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRequestingImageManipulation)
|
|
||||||
{
|
|
||||||
etag = Utilities.GenerateSimpleHash(Request.QueryString.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
etag = Convert.ToString(file.ModifiedOn.Ticks ^ file.Size, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
var header = "";
|
|
||||||
if (HttpContext.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var ifNoneMatch))
|
|
||||||
{
|
|
||||||
header = ifNoneMatch.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (header.Equals(etag))
|
|
||||||
{
|
|
||||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
|
|
||||||
return Content(String.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!System.IO.File.Exists(filepath))
|
|
||||||
{
|
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Read, "File Does Not Exist {FilePath}", filepath);
|
|
||||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
|
||||||
return BrokenFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRequestingImageManipulation)
|
if (isRequestingImageManipulation)
|
||||||
{
|
{
|
||||||
var _ImageFiles = _settingRepository.GetSetting(EntityNames.Site, _alias.SiteId, "ImageFiles")?.SettingValue;
|
var _ImageFiles = _settingRepository.GetSetting(EntityNames.Site, _alias.SiteId, "ImageFiles")?.SettingValue;
|
||||||
|
Reference in New Issue
Block a user