Skip to content

Commit

Permalink
Merge pull request #323 from SixLabors/js/critical-fix-decoder-options
Browse files Browse the repository at this point in the history
Fix DecoderOptions handler.
  • Loading branch information
JimBobSquarePants authored Apr 5, 2023
2 parents 4fdc000 + 6071b4e commit 67e82ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Web/Middleware/ImageSharpMiddlewareOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ImageSharpMiddlewareOptions
};

private Func<ImageCommandContext, Task> onParseCommandsAsync = _ => Task.CompletedTask;
private Func<ImageCommandContext, DecoderOptions, Task> onBeforeLoadAsync = (_, _) => Task.CompletedTask;
private Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> onBeforeLoadAsync = (_, _) => Task.FromResult<DecoderOptions?>(null);
private Func<FormattedImage, Task> onBeforeSaveAsync = _ => Task.CompletedTask;
private Func<ImageProcessingContext, Task> onProcessedAsync = _ => Task.CompletedTask;
private Func<HttpContext, Task> onPrepareResponseAsync = _ => Task.CompletedTask;
Expand Down Expand Up @@ -118,7 +118,7 @@ public Func<ImageCommandContext, Task> 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.
/// </summary>
public Func<ImageCommandContext, DecoderOptions, Task> OnBeforeLoadAsync
public Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> OnBeforeLoadAsync
{
get => this.onBeforeLoadAsync;

Expand Down
8 changes: 4 additions & 4 deletions tests/ImageSharp.Web.Tests/TestUtilities/TestServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ protected void ConfigureServices(IServiceCollection services)
return onParseCommandsAsync.Invoke(context);
};

Func<ImageCommandContext, DecoderOptions, Task> onBeforeLoadAsync = options.OnBeforeLoadAsync;
Func<ImageCommandContext, Configuration, Task<DecoderOptions?>> 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<ImageProcessingContext, Task> onProcessedAsync = options.OnProcessedAsync;
Expand Down

0 comments on commit 67e82ab

Please sign in to comment.