From 917c79eaeb87e44763ee5e0abe4436806d6749bf Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 24 May 2023 17:09:25 +0500 Subject: [PATCH] Add compression --- AsbCloudWebApi/Startup.cs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/AsbCloudWebApi/Startup.cs b/AsbCloudWebApi/Startup.cs index 1fd833cb..6d14e3dc 100644 --- a/AsbCloudWebApi/Startup.cs +++ b/AsbCloudWebApi/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.ResponseCompression; namespace AsbCloudWebApi { @@ -96,7 +97,11 @@ namespace AsbCloudWebApi }); }); - + services.AddResponseCompression(options => + { + options.EnableForHttps = true; + options.Providers.Add(); + }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -115,23 +120,22 @@ namespace AsbCloudWebApi app.UseDeveloperExceptionPage(); } - //app.UseHttpsRedirection(); app.UseDefaultFiles(); app.UseStaticFiles( - //new StaticFileOptions - //{ - // OnPrepareResponse = ctx => - // { - // ctx.Context.Response.Headers.CacheControl = "public,max-age=2592000"; - // ctx.Context.Response.Headers.Expires = DateTime.UtcNow.AddDays(10).ToString("R", CultureInfo.InvariantCulture); - // } - //} + new StaticFileOptions + { + OnPrepareResponse = ctx => + { + ctx.Context.Response.Headers.CacheControl = "public,max-age=2592000"; + ctx.Context.Response.Headers.Expires = System.DateTime.UtcNow.AddDays(10).ToString("R", System.Globalization.CultureInfo.InvariantCulture); + } + } ); app.UseCors("ClientPermission"); app.UseRouting(); app.UseResponseCaching(); - //app.UseResponseCompression(); + app.UseResponseCompression(); app.UseAuthentication(); app.UseAuthorization();