yuanrf 3 天之前
父节点
当前提交
2dfa80273d
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      OASystem/OASystem.Api/Program.cs

+ 21 - 0
OASystem/OASystem.Api/Program.cs

@@ -1,5 +1,6 @@
 using Microsoft.AspNetCore.Http.Connections;
 using Microsoft.AspNetCore.Http.Features;
+using Microsoft.AspNetCore.ResponseCompression;
 using Microsoft.AspNetCore.Server.Kestrel.Core;
 using Microsoft.Extensions.DependencyInjection.Extensions;
 using OASystem.API.Middlewares;
@@ -17,6 +18,7 @@ using Quartz.Spi;
 using QuzrtzJob.Factory;
 using Serilog.Events;
 using System.Diagnostics;
+using System.IO.Compression;
 
 Console.Title = $"FMGJ OASystem Server";
 var builder = WebApplication.CreateBuilder(args);
@@ -77,6 +79,21 @@ builder.Services.AddControllers()
 
 builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
 
+#region Gzip
+
+builder.Services.AddResponseCompression(options =>
+{
+    options.EnableForHttps = true;
+    options.Providers.Add<GzipCompressionProvider>();
+});
+
+builder.Services.Configure<GzipCompressionProviderOptions>(options =>
+{
+    options.Level = CompressionLevel.Optimal;
+});
+
+#endregion
+
 #region Cors
 builder.Services.AddCors(policy =>
 {
@@ -497,6 +514,10 @@ app.UseMiddleware<RecordAPIOperationMiddleware>();
 app.UseAuthentication(); // ÈÏÖ¤
 app.UseAuthorization();  // ÊÚȨ
 
+app.UseWhen(context =>
+    context.Request.Path.StartsWithSegments("/api/MarketCustomerResources/QueryNewClientData"),
+    branch => branch.UseResponseCompression());
+
 // ÊÚȨ·¾¶
 //app.MapGet("generatetoken", c => c.Response.WriteAsync(JWTBearer.GenerateToken(c)));