From a6ea3c83fc0e4a5838d34c708e5d94679768f907 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 5 Apr 2023 23:12:13 +1000 Subject: [PATCH 1/2] Fix DecoderOptions handler. --- src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs | 5 ++--- src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs b/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs index 07c3bf51..72fc2146 100644 --- a/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs +++ b/src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs @@ -343,10 +343,9 @@ private async Task ProcessRequestAsync( using (Stream inStream = await sourceImageResolver.OpenReadAsync()) { - DecoderOptions decoderOptions = new() { Configuration = this.options.Configuration }; - // TODO: Do we need some way to set options based upon processors? - await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, decoderOptions); + DecoderOptions decoderOptions = await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, this.options.Configuration) + ?? new() { Configuration = this.options.Configuration }; FormattedImage? image = null; try diff --git a/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs b/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs index 8b10dc9d..82c71984 100644 --- a/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs +++ b/src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs @@ -27,7 +27,7 @@ public class ImageSharpMiddlewareOptions }; private Func onParseCommandsAsync = _ => Task.CompletedTask; - private Func onBeforeLoadAsync = (_, _) => Task.CompletedTask; + private Func> onBeforeLoadAsync = (_, _) => Task.FromResult(null); private Func onBeforeSaveAsync = _ => Task.CompletedTask; private Func onProcessedAsync = _ => Task.CompletedTask; private Func onPrepareResponseAsync = _ => Task.CompletedTask; @@ -118,7 +118,7 @@ public Func OnParseCommandsAsync /// Gets or sets the method that can be used to used to augment decoder options. /// This is called before the image is decoded and loaded for processing. /// - public Func OnBeforeLoadAsync + public Func> OnBeforeLoadAsync { get => this.onBeforeLoadAsync; From 6071b4ed91e9a166e95df947aaad143943587438 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 5 Apr 2023 23:18:43 +1000 Subject: [PATCH 2/2] Update TestServerFixture.cs --- .../TestUtilities/TestServerFixture.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs b/tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs index 4db2c263..bab86ef6 100644 --- a/tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs +++ b/tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs @@ -68,14 +68,14 @@ protected void ConfigureServices(IServiceCollection services) return onParseCommandsAsync.Invoke(context); }; - Func onBeforeLoadAsync = options.OnBeforeLoadAsync; + Func> onBeforeLoadAsync = options.OnBeforeLoadAsync; - options.OnBeforeLoadAsync = (context, decoderOptions) => + options.OnBeforeLoadAsync = (context, configuration) => { Assert.NotNull(context); - Assert.NotNull(decoderOptions); + Assert.NotNull(configuration); - return onBeforeLoadAsync.Invoke(context, decoderOptions); + return onBeforeLoadAsync.Invoke(context, configuration); }; Func onProcessedAsync = options.OnProcessedAsync;