平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GzipCompressionComponent.cs 962 B

3 months ago
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. }