TlsRestoreMiddleware.cs 801 B

123456789101112131415161718192021222324252627
  1. using Microsoft.AspNetCore.Connections;
  2. using Microsoft.AspNetCore.Http.Features;
  3. using System.Threading.Tasks;
  4. namespace FastGithub.HttpServer.TlsMiddlewares
  5. {
  6. /// <summary>
  7. /// https恢复中间件
  8. /// </summary>
  9. sealed class TlsRestoreMiddleware
  10. {
  11. /// <summary>
  12. /// 执行中间件
  13. /// </summary>
  14. /// <param name="context"></param>
  15. /// <returns></returns>
  16. public async Task InvokeAsync(ConnectionDelegate next, ConnectionContext context)
  17. {
  18. if (context.Features.Get<ITlsConnectionFeature>() == FakeTlsConnectionFeature.Instance)
  19. {
  20. // 擦除入侵
  21. context.Features.Set<ITlsConnectionFeature>(null);
  22. }
  23. await next(context);
  24. }
  25. }
  26. }