Add compression

This commit is contained in:
ngfrolov 2023-05-24 17:09:25 +05:00
parent 1061cee0cf
commit 917c79eaeb
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -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<GzipCompressionProvider>();
});
}
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();