ReverseProxyApplicationBuilderExtensions.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using FastGithub.ReverseProxy;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.Extensions.DependencyInjection;
  4. namespace FastGithub
  5. {
  6. /// <summary>
  7. /// https反向代理的中间件扩展
  8. /// </summary>
  9. public static class ReverseProxyApplicationBuilderExtensions
  10. {
  11. /// <summary>
  12. /// 使用请求日志中间件
  13. /// </summary>
  14. /// <param name="app"></param>
  15. /// <returns></returns>
  16. public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app)
  17. {
  18. var middlware = app.ApplicationServices.GetRequiredService<RequestLoggingMilldeware>();
  19. return app.Use(next => context => middlware.InvokeAsync(context, next));
  20. }
  21. /// <summary>
  22. /// 使用https反向代理中间件
  23. /// </summary>
  24. /// <param name="app"></param>
  25. /// <returns></returns>
  26. public static IApplicationBuilder UseHttpsReverseProxy(this IApplicationBuilder app)
  27. {
  28. var middleware = app.ApplicationServices.GetRequiredService<ReverseProxyMiddleware>();
  29. return app.Use(next => context => middleware.InvokeAsync(context, next));
  30. }
  31. }
  32. }