mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:30:49 +08:00 
			
		
		
		
	initial commit for new feature #1077
allow to limit the number of concurrent tcp connection to a downstream service
This commit is contained in:
		@@ -19,7 +19,7 @@
 | 
			
		||||
            var useTracing = _tracer != null && options.UseTracing;
 | 
			
		||||
 | 
			
		||||
            return new HttpHandlerOptions(options.AllowAutoRedirect,
 | 
			
		||||
                options.UseCookieContainer, useTracing, options.UseProxy);
 | 
			
		||||
                options.UseCookieContainer, useTracing, options.UseProxy, options.MaxConnectionsPerServer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,8 @@
 | 
			
		||||
        {
 | 
			
		||||
            AllowAutoRedirect = false;
 | 
			
		||||
            UseCookieContainer = false;
 | 
			
		||||
            UseProxy = true;
 | 
			
		||||
            UseProxy = true;
 | 
			
		||||
            MaxConnectionsPerServer = int.MaxValue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool AllowAutoRedirect { get; set; }
 | 
			
		||||
@@ -15,6 +16,8 @@
 | 
			
		||||
 | 
			
		||||
        public bool UseTracing { get; set; }
 | 
			
		||||
 | 
			
		||||
        public bool UseProxy { get; set; }
 | 
			
		||||
        public bool UseProxy { get; set; }
 | 
			
		||||
 | 
			
		||||
        public int MaxConnectionsPerServer { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,32 +6,44 @@
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class HttpHandlerOptions
 | 
			
		||||
    {
 | 
			
		||||
        public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing, bool useProxy)
 | 
			
		||||
        {
 | 
			
		||||
            AllowAutoRedirect = allowAutoRedirect;
 | 
			
		||||
            UseCookieContainer = useCookieContainer;
 | 
			
		||||
            UseTracing = useTracing;
 | 
			
		||||
            UseProxy = useProxy;
 | 
			
		||||
        public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing, bool useProxy, int maxConnectionsPerServer)
 | 
			
		||||
        {
 | 
			
		||||
            AllowAutoRedirect = allowAutoRedirect;
 | 
			
		||||
            UseCookieContainer = useCookieContainer;
 | 
			
		||||
            UseTracing = useTracing;
 | 
			
		||||
            UseProxy = useProxy;
 | 
			
		||||
            MaxConnectionsPerServer = maxConnectionsPerServer;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Specify if auto redirect is enabled
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool AllowAutoRedirect { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>AllowAutoRedirect</value>
 | 
			
		||||
        public bool AllowAutoRedirect { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Specify is handler has to use a cookie container
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>UseCookieContainer</value>
 | 
			
		||||
        public bool UseCookieContainer { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Specify is handler has to use a opentracing
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>UseTracing</value>
 | 
			
		||||
        public bool UseTracing { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Specify if handler has to use a proxy
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool UseProxy { get; private set; }
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>UseProxy</value>
 | 
			
		||||
        public bool UseProxy { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Specify the maximum of concurrent connection to a network endpoint
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>MaxConnectionsPerServer</value>
 | 
			
		||||
        public int MaxConnectionsPerServer { get; private set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
        private bool _useCookieContainer;
 | 
			
		||||
        private bool _useTracing;
 | 
			
		||||
        private bool _useProxy;
 | 
			
		||||
        private int _maxConnectionPerServer;
 | 
			
		||||
 | 
			
		||||
        public HttpHandlerOptionsBuilder WithAllowAutoRedirect(bool input)
 | 
			
		||||
        {
 | 
			
		||||
@@ -30,10 +31,16 @@
 | 
			
		||||
            _useProxy = useProxy;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
        public HttpHandlerOptionsBuilder WithUseMaxConnectionPerServer(int maxConnectionPerServer)
 | 
			
		||||
        {
 | 
			
		||||
            _maxConnectionPerServer = maxConnectionPerServer;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public HttpHandlerOptions Build()
 | 
			
		||||
        {
 | 
			
		||||
            return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing, _useProxy);
 | 
			
		||||
            return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing, _useProxy, _maxConnectionPerServer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -90,7 +90,9 @@ namespace Ocelot.Requester
 | 
			
		||||
            {
 | 
			
		||||
                AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
 | 
			
		||||
                UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
 | 
			
		||||
                UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy
 | 
			
		||||
                UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy,
 | 
			
		||||
                MaxConnectionsPerServer = context.DownstreamReRoute.HttpHandlerOptions.MaxConnectionsPerServer
 | 
			
		||||
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -101,6 +103,7 @@ namespace Ocelot.Requester
 | 
			
		||||
                AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
 | 
			
		||||
                UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
 | 
			
		||||
                UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy,
 | 
			
		||||
                MaxConnectionsPerServer = context.DownstreamReRoute.HttpHandlerOptions.MaxConnectionsPerServer,
 | 
			
		||||
                CookieContainer = new CookieContainer()
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user