Skip to content

Commit a6ea3c8

Browse files
Fix DecoderOptions handler.
1 parent 4fdc000 commit a6ea3c8

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,9 @@ private async Task ProcessRequestAsync(
343343

344344
using (Stream inStream = await sourceImageResolver.OpenReadAsync())
345345
{
346-
DecoderOptions decoderOptions = new() { Configuration = this.options.Configuration };
347-
348346
// TODO: Do we need some way to set options based upon processors?
349-
await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, decoderOptions);
347+
DecoderOptions decoderOptions = await this.options.OnBeforeLoadAsync.Invoke(imageCommandContext, this.options.Configuration)
348+
?? new() { Configuration = this.options.Configuration };
350349

351350
FormattedImage? image = null;
352351
try

src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ImageSharpMiddlewareOptions
2727
};
2828

2929
private Func<ImageCommandContext, Task> onParseCommandsAsync = _ => Task.CompletedTask;
30-
private Func<ImageCommandContext, DecoderOptions, Task> onBeforeLoadAsync = (_, _) => Task.CompletedTask;
30+
private Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> onBeforeLoadAsync = (_, _) => Task.FromResult<DecoderOptions?>(null);
3131
private Func<FormattedImage, Task> onBeforeSaveAsync = _ => Task.CompletedTask;
3232
private Func<ImageProcessingContext, Task> onProcessedAsync = _ => Task.CompletedTask;
3333
private Func<HttpContext, Task> onPrepareResponseAsync = _ => Task.CompletedTask;
@@ -118,7 +118,7 @@ public Func<ImageCommandContext, Task> OnParseCommandsAsync
118118
/// Gets or sets the method that can be used to used to augment decoder options.
119119
/// This is called before the image is decoded and loaded for processing.
120120
/// </summary>
121-
public Func<ImageCommandContext, DecoderOptions, Task> OnBeforeLoadAsync
121+
public Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> OnBeforeLoadAsync
122122
{
123123
get => this.onBeforeLoadAsync;
124124

0 commit comments

Comments
 (0)