Merge branch 'feature/httphandler-maxconnectionperserver' of https://github.com/buretjph/Ocelot into buretjph-feature/httphandler-maxconnectionperserver

This commit is contained in:
TomPallister
2020-01-19 10:58:31 +00:00
9 changed files with 115 additions and 48 deletions

View File

@ -18,8 +18,11 @@
{
var useTracing = _tracer != null && options.UseTracing;
//be sure that maxConnectionPerServer is in correct range of values
int maxConnectionPerServer = (options.MaxConnectionsPerServer > 0) ? maxConnectionPerServer = options.MaxConnectionsPerServer : maxConnectionPerServer = int.MaxValue;
return new HttpHandlerOptions(options.AllowAutoRedirect,
options.UseCookieContainer, useTracing, options.UseProxy);
options.UseCookieContainer, useTracing, options.UseProxy, maxConnectionPerServer);
}
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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);
}
}
}

View File

@ -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()
};
}