v11: Decouple dependencies (#12907)
* Move core dependencies and MSBuild targets from Umbraco.Cms to Umbraco.Cms.Targets * Re-add appsettings.Tests.json * Include appsettings-schema.json * Use .NET 7.x in CodeQL build * Fix duplicate Directory.Build.props import * Decouple ImageSharp/ImageSharp.Web implementations * Further decouple SqlServer implementation * Add SupportedImageFileTypes to IImageDimensionExtractor * Update descriptions * Update project metadata * Re-enable package validation * Add embedded package icon * Move ContinuousIntegrationBuild to build script * Move shared properties to root Directory.Build.props * Fix GetInstallState throwing exception when default provider isn't configured * Remove redundant PackageRequireLicenseAcceptance and update version to 11.0.0-rc1 * Update build script * Remove LangVersion preview * Disable app-local ICU for MacOS integration test * Disable app-local ICU for all integration tests * Fix RuntimeState_Run test assertion * Update projects and build script to require Node.js 16.17 (latest LTS) * Remove app-local ICU from unit tests * Add missing project reference * Generate XML documentation files * Expose management API in Web.UI project * Update .NET 7 dependencies to RC1 * Update package-lock.json files * Downgrade Cypress version
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Headers;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Web.Commands;
|
||||
using SixLabors.ImageSharp.Web.Middleware;
|
||||
using SixLabors.ImageSharp.Web.Processors;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
namespace Umbraco.Cms.Imaging.ImageSharp;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the ImageSharp middleware options.
|
||||
/// </summary>
|
||||
/// <seealso cref="IConfigureOptions{ImageSharpMiddlewareOptions}" />
|
||||
public sealed class ConfigureImageSharpMiddlewareOptions : IConfigureOptions<ImageSharpMiddlewareOptions>
|
||||
{
|
||||
private readonly Configuration _configuration;
|
||||
private readonly ImagingSettings _imagingSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ConfigureImageSharpMiddlewareOptions" /> class.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The ImageSharp configuration.</param>
|
||||
/// <param name="imagingSettings">The Umbraco imaging settings.</param>
|
||||
public ConfigureImageSharpMiddlewareOptions(Configuration configuration, IOptions<ImagingSettings> imagingSettings)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_imagingSettings = imagingSettings.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Configure(ImageSharpMiddlewareOptions options)
|
||||
{
|
||||
options.Configuration = _configuration;
|
||||
|
||||
options.BrowserMaxAge = _imagingSettings.Cache.BrowserMaxAge;
|
||||
options.CacheMaxAge = _imagingSettings.Cache.CacheMaxAge;
|
||||
options.CacheHashLength = _imagingSettings.Cache.CacheHashLength;
|
||||
|
||||
// Use configurable maximum width and height
|
||||
options.OnParseCommandsAsync = context =>
|
||||
{
|
||||
if (context.Commands.Count == 0)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var width = context.Parser.ParseValue<int>(
|
||||
context.Commands.GetValueOrDefault(ResizeWebProcessor.Width),
|
||||
context.Culture);
|
||||
if (width <= 0 || width > _imagingSettings.Resize.MaxWidth)
|
||||
{
|
||||
context.Commands.Remove(ResizeWebProcessor.Width);
|
||||
}
|
||||
|
||||
var height = context.Parser.ParseValue<int>(
|
||||
context.Commands.GetValueOrDefault(ResizeWebProcessor.Height),
|
||||
context.Culture);
|
||||
if (height <= 0 || height > _imagingSettings.Resize.MaxHeight)
|
||||
{
|
||||
context.Commands.Remove(ResizeWebProcessor.Height);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
// Change Cache-Control header when cache buster value is present
|
||||
options.OnPrepareResponseAsync = context =>
|
||||
{
|
||||
if (context.Request.Query.ContainsKey("rnd") || context.Request.Query.ContainsKey("v"))
|
||||
{
|
||||
ResponseHeaders headers = context.Response.GetTypedHeaders();
|
||||
|
||||
CacheControlHeaderValue cacheControl =
|
||||
headers.CacheControl ?? new CacheControlHeaderValue { Public = true };
|
||||
cacheControl.MustRevalidate = false; // ImageSharp enables this by default
|
||||
cacheControl.Extensions.Add(new NameValueHeaderValue("immutable"));
|
||||
|
||||
headers.CacheControl = cacheControl;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user