using FastGithub.HttpServer.HttpMiddlewares;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace FastGithub
{
    /// 
    /// ApplicationBuilder扩展
    /// 
    public static class ApplicationBuilderExtensions
    {
        /// 
        /// 使用http代理策略中间件
        /// 
        ///  
        /// 
        public static IApplicationBuilder UseHttpProxyPac(this IApplicationBuilder app)
        {
            var middleware = app.ApplicationServices.GetRequiredService();
            return app.Use(next => context => middleware.InvokeAsync(context, next));
        }
        /// 
        /// 使用请求日志中间件
        /// 
        ///  
        /// 
        public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder app)
        {
            var middleware = app.ApplicationServices.GetRequiredService();
            return app.Use(next => context => middleware.InvokeAsync(context, next));
        }
        /// 
        /// 禁用请求日志中间件
        /// 
        /// 
        /// 
        public static IApplicationBuilder DisableRequestLogging(this IApplicationBuilder app)
        {
            return app.Use(next => context =>
            {
                var loggingFeature = context.Features.Get();
                if (loggingFeature != null)
                {
                    loggingFeature.Enable = false;
                }
                return next(context);
            });
        }
        /// 
        /// 使用反向代理中间件
        /// 
        ///  
        /// 
        public static IApplicationBuilder UseHttpReverseProxy(this IApplicationBuilder app)
        {
            var middleware = app.ApplicationServices.GetRequiredService();
            return app.Use(next => context => middleware.InvokeAsync(context, next));
        }
    }
}