Skip to content

Commit 67e82ab

Browse files
Merge pull request #323 from SixLabors/js/critical-fix-decoder-options
Fix DecoderOptions handler.
2 parents 4fdc000 + 6071b4e commit 67e82ab

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
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

tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ protected void ConfigureServices(IServiceCollection services)
6868
return onParseCommandsAsync.Invoke(context);
6969
};
7070

71-
Func<ImageCommandContext, DecoderOptions, Task> onBeforeLoadAsync = options.OnBeforeLoadAsync;
71+
Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> onBeforeLoadAsync = options.OnBeforeLoadAsync;
7272

73-
options.OnBeforeLoadAsync = (context, decoderOptions) =>
73+
options.OnBeforeLoadAsync = (context, configuration) =>
7474
{
7575
Assert.NotNull(context);
76-
Assert.NotNull(decoderOptions);
76+
Assert.NotNull(configuration);
7777

78-
return onBeforeLoadAsync.Invoke(context, decoderOptions);
78+
return onBeforeLoadAsync.Invoke(context, configuration);
7979
};
8080

8181
Func<ImageProcessingContext, Task> onProcessedAsync = options.OnProcessedAsync;

0 commit comments

Comments
 (0)