平安校园
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GzipCompressionComponent.cs 962 B

4 个月前
123456789101112131415161718192021222324252627282930313233
  1. 
  2. //
  3. namespace SafeCampus.Core;
  4. /// <summary>
  5. /// Gzip压缩组件
  6. /// </summary>
  7. public sealed class GzipCompressionComponent : IServiceComponent
  8. {
  9. public void Load(IServiceCollection services, ComponentContext componentContext)
  10. {
  11. services.Configure<BrotliCompressionProviderOptions>(options => { options.Level = CompressionLevel.Optimal; });
  12. services.Configure<GzipCompressionProviderOptions>(options => { options.Level = CompressionLevel.Optimal; });
  13. services.AddResponseCompression(options =>
  14. {
  15. options.EnableForHttps = true;
  16. options.Providers.Add<BrotliCompressionProvider>();
  17. options.Providers.Add<GzipCompressionProvider>();
  18. options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
  19. {
  20. "text/html; charset=utf-8", "application/xhtml+xml", "application/atom+xml", "image/svg+xml"
  21. });
  22. });
  23. }
  24. }