Marian
04/08/2024, 10:32 AMCorné Hoskam
04/08/2024, 11:07 AMMarian
04/08/2024, 11:22 AMCorné Hoskam
04/08/2024, 11:33 AMpublic class WebPConversionMiddleware
{
private readonly RequestDelegate _next;
public WebPConversionMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
var request = context.Request;
var path = request.Path;
// Check if the requested URL ends with .png
if (path.HasValue && path.Value.EndsWith(".png"))
{
// Append ?format=webp to the query string
var newUrl = $"{path}?format=webp";
context.Request.Path = newUrl;
}
await _next(context);
}
}
}
Marian
04/08/2024, 11:44 AMMike Chambers
04/08/2024, 12:32 PMMatt Wise
04/08/2024, 12:37 PMMatt Wise
04/08/2024, 12:37 PMMike Chambers
04/08/2024, 1:11 PMbuilder.Services.AddTransient<IConfigureOptions<ImageSharpMiddlewareOptions>, CustomWebpImageSharpMiddlewareOptions>();
in a composer say to add your extra middleware?
So as not to affect umbraco core?
https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Cms.Imaging.ImageSharp/UmbracoBuilderExtensions.cs#L37
or maybe like this?
https://github.com/umbraco/Umbraco-CMS/discussions/10840#discussioncomment-1166843Marian
04/24/2024, 4:28 PMCorné Hoskam
04/24/2024, 8:18 PMCraig100
04/25/2024, 10:27 PMMatt Wise
04/26/2024, 5:42 AMMike Chambers
04/26/2024, 7:40 AMDean Leigh
04/26/2024, 8:44 AMCraig100
04/26/2024, 8:49 AMCraig100
04/26/2024, 8:49 AMCraig100
04/26/2024, 8:50 AMCraig100
04/26/2024, 8:50 AMskttl
04/26/2024, 8:56 AMCraig100
04/26/2024, 8:56 AMskttl
04/26/2024, 8:57 AMCraig100
04/26/2024, 9:00 AMkdx-perbol
04/26/2024, 11:04 AMWebPConversionMiddleware
seems like it could cover more cases, including third-party images from packages/Forms etc.