Skip to content

Commit a0efff2

Browse files
committed
avoids weirdness with await and nullable callbacks
1 parent f8a49d1 commit a0efff2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ImageSharp.Web/Middleware/ImageContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ private async Task ApplyResponseHeadersAsync(int statusCode, string contentType,
192192
MustRevalidate = true
193193
};
194194

195-
await this.options.OnPrepareResponse?.Invoke(this.context);
195+
if (this.options.OnPrepareResponse != null)
196+
{
197+
await this.options.OnPrepareResponse.Invoke(this.context);
198+
}
196199
}
197200

198201
if (statusCode == ResponseConstants.Status200Ok)

src/ImageSharp.Web/Middleware/ImageSharpMiddleware.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ public async Task Invoke(HttpContext context)
167167
}
168168
}
169169

170-
await this.options.OnParseCommands?.Invoke(new ImageCommandContext(context, commands, CommandParser.Instance));
170+
if (this.options.OnParseCommands != null)
171+
{
172+
await this.options.OnParseCommands.Invoke(new ImageCommandContext(context, commands, CommandParser.Instance));
173+
}
171174

172175
// Get the correct service for the request.
173176
IImageProvider provider = null;
@@ -273,7 +276,11 @@ private async Task ProcessRequestAsync(HttpContext context, bool processRequest,
273276
using (var image = FormattedImage.Load(this.options.Configuration, inStream))
274277
{
275278
image.Process(this.logger, this.processors, commands);
276-
await this.options.OnBeforeSave?.Invoke(image);
279+
if (this.options.OnBeforeSave != null)
280+
{
281+
await this.options.OnBeforeSave.Invoke(image);
282+
}
283+
277284
image.Save(outStream);
278285
format = image.Format;
279286
}
@@ -298,7 +305,11 @@ private async Task ProcessRequestAsync(HttpContext context, bool processRequest,
298305
outStream.Position = 0;
299306
string contentType = cachedImageMetadata.ContentType;
300307
string extension = this.formatUtilities.GetExtensionFromContentType(contentType);
301-
await this.options.OnProcessed?.Invoke(new ImageProcessingContext(context, outStream, commands, contentType, extension));
308+
if (this.options.OnProcessed != null)
309+
{
310+
await this.options.OnProcessed.Invoke(new ImageProcessingContext(context, outStream, commands, contentType, extension));
311+
}
312+
302313
outStream.Position = 0;
303314

304315
// Save the image to the cache and send the response to the caller.

0 commit comments

Comments
 (0)