diff --git a/AdLerBackend.API/ConfigureServices.cs b/AdLerBackend.API/ConfigureServices.cs index 36e623c..cb58b08 100644 --- a/AdLerBackend.API/ConfigureServices.cs +++ b/AdLerBackend.API/ConfigureServices.cs @@ -1,6 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; using AdLerBackend.API.Filters; +using AdLerBackend.API.Middleware; using AdLerBackend.Application.Configuration; using Microsoft.AspNetCore.Http.Features; using UnzipMiddleware; @@ -21,7 +22,7 @@ public static class ConfigureServices public static IServiceCollection AddApiServices(this IServiceCollection services) { services - .AddControllers(options => options.Filters.Add()); + .AddControllers(options => { options.Filters.Add(); }); services.AddHttpContextAccessor(); @@ -72,6 +73,7 @@ public static WebApplication ConfigureApp(this WebApplication app) RootPath = "wwwroot", ZipFileExtensions = new[] {".h5p"} }); + app.UseMiddleware(); app.UseStaticFiles(new StaticFileOptions { ServeUnknownFileTypes = true diff --git a/AdLerBackend.API/Middleware/DefaultContentTypeMiddleware.cs b/AdLerBackend.API/Middleware/DefaultContentTypeMiddleware.cs new file mode 100644 index 0000000..03e85eb --- /dev/null +++ b/AdLerBackend.API/Middleware/DefaultContentTypeMiddleware.cs @@ -0,0 +1,13 @@ +namespace AdLerBackend.API.Middleware; + +public class DefaultContentTypeMiddleware(RequestDelegate next) +{ + public async Task InvokeAsync(HttpContext context) + { + if (string.IsNullOrEmpty(context.Request.ContentType) && + context.Request.Method is "POST" or "PUT" or "PATCH") + context.Request.ContentType = "application/json"; + + await next(context); + } +} \ No newline at end of file