Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions docs/features/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,10 @@ based on a `SocketsHttpHandler <https://github.com/search?q=repo%3AThreeMammals%
"MaxConnectionsPerServer": 2147483647, // max integer
"PooledConnectionLifetimeSeconds": 120,
"UseCookieContainer": false,
"UseProxy": false,
"UseTracing": false
}

.. list-table::
:widths: 25 75
:header-rows: 1
"UseTracing": true,
"MaxConnectionsPerServer": 100,
"EnableMultipleHttp2Connections": false
},

* - *Option*
- *Description*
Expand Down Expand Up @@ -626,6 +623,9 @@ based on a `SocketsHttpHandler <https://github.com/search?q=repo%3AThreeMammals%
4. Prior to version `24.1`_, global ``HttpHandlerOptions`` were not accessible, as they were only available at the route level for static routes.
Since version `24.1`_, global configuration is supported for both static and dynamic routes.

* **EnableMultipleHttp2Connections** Gets or sets a value that indicates whether additional HTTP/2 connections can be established to the same server.
true if additional HTTP/2 connections are allowed to be created; otherwise, false.

.. _ssl-errors:

SSL Errors
Expand Down Expand Up @@ -708,6 +708,11 @@ HTTP2 version policy
"DownstreamHttpVersion": "2.0",
"DownstreamHttpVersionPolicy": "", // empty or not defined
"DangerousAcceptAnyServerCertificateValidator": true
"DownstreamHttpVersionPolicy": "", // empty
"DangerousAcceptAnyServerCertificateValidator": true,
"HttpHandlerOptions":{
"EnableMultipleHttp2Connections": true
}
}

**And** you configure global settings to use :ref:`hosting-gotchas-kestrel` with this snippet:
Expand Down Expand Up @@ -738,7 +743,10 @@ Therefore, the ``DownstreamHttpVersionPolicy`` should be defined as follows:

{
"DownstreamHttpVersion": "2.0",
"DownstreamHttpVersionPolicy": "RequestVersionOrHigher" // !
"DownstreamHttpVersionPolicy": "RequestVersionOrHigher", // !
"HttpHandlerOptions":{
"EnableMultipleHttp2Connections": true
}
}

Dependency Injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected virtual HttpHandlerOptions Merge(FileHttpHandlerOptions options, FileH
options.UseCookieContainer ??= globalOptions.UseCookieContainer ?? false;
options.UseProxy ??= globalOptions.UseProxy ?? false;
options.UseTracing ??= globalOptions.UseTracing ?? false;
options.EnableMultipleHttp2Connections ??= globalOptions.EnableMultipleHttp2Connections ?? false; // TODO true ?
var useTracing = _tracer != null && options.UseTracing.Value;
return new(options, useTracing);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ocelot/Configuration/File/FileHttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public FileHttpHandlerOptions(FileHttpHandlerOptions from)
UseCookieContainer = from.UseCookieContainer;
UseProxy = from.UseProxy;
UseTracing = from.UseTracing;
EnableMultipleHttp2Connections = from.EnableMultipleHttp2Connections;
}

public bool? AllowAutoRedirect { get; set; }
public bool? EnableMultipleHttp2Connections { get; set; }
public int? MaxConnectionsPerServer { get; set; }
public int? PooledConnectionLifetimeSeconds { get; set; }
public bool? UseCookieContainer { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions src/Ocelot/Configuration/HttpHandlerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public HttpHandlerOptions()
public HttpHandlerOptions(FileHttpHandlerOptions from)
{
AllowAutoRedirect = from.AllowAutoRedirect ?? false;
EnableMultipleHttp2Connections = from.EnableMultipleHttp2Connections ?? false; // TODO true ?
MaxConnectionsPerServer = from.MaxConnectionsPerServer.HasValue && from.MaxConnectionsPerServer.Value > 0
? from.MaxConnectionsPerServer.Value : int.MaxValue;
PooledConnectionLifeTime = TimeSpan.FromSeconds(from.PooledConnectionLifetimeSeconds ?? DefaultPooledConnectionLifetimeSeconds);
Expand All @@ -38,6 +39,12 @@ public HttpHandlerOptions(FileHttpHandlerOptions from, bool useTracing)
/// <value>AllowAutoRedirect.</value>
public bool AllowAutoRedirect { get; init; }

/// <summary>
/// Gets or sets a value that indicates whether additional HTTP/2 connections can be established to the same server.
/// </summary>
/// <value>EnableMultipleHttp2Connections.</value>
public bool EnableMultipleHttp2Connections { get; }

/// <summary>
/// Specify is handler has to use a cookie container.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/Requester/MessageInvokerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected virtual SocketsHttpHandler CreateHandler(DownstreamRoute route)
var handler = new SocketsHttpHandler
{
AllowAutoRedirect = options.AllowAutoRedirect,
EnableMultipleHttp2Connections = options.EnableMultipleHttp2Connections,
UseCookies = options.UseCookieContainer,
UseProxy = options.UseProxy,
MaxConnectionsPerServer = options.MaxConnectionsPerServer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Ocelot.Configuration;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Logging;
using Ocelot.Logging;
using System.Reflection;

namespace Ocelot.UnitTests.Configuration;
Expand Down Expand Up @@ -297,6 +297,7 @@ public void Merge(bool isDef, bool hasTracer)
FileHttpHandlerOptions options = new()
{
AllowAutoRedirect = isDef ? null : true,
EnableMultipleHttp2Connections = isDef ? null : true,
MaxConnectionsPerServer = isDef ? null : 333,
PooledConnectionLifetimeSeconds = isDef ? null : 333,
UseCookieContainer = isDef ? null : true,
Expand All @@ -306,6 +307,7 @@ public void Merge(bool isDef, bool hasTracer)
FileHttpHandlerOptions globalOptions = new()
{
AllowAutoRedirect = isDef ? null : false,
EnableMultipleHttp2Connections = isDef ? null : false,
MaxConnectionsPerServer = isDef ? null : 111,
PooledConnectionLifetimeSeconds = isDef ? null : 111,
UseCookieContainer = isDef ? null : false,
Expand All @@ -318,6 +320,7 @@ public void Merge(bool isDef, bool hasTracer)

// Assert
Assert.Equal(!isDef, actual.AllowAutoRedirect);
Assert.Equal(!isDef, actual.EnableMultipleHttp2Connections);
Assert.Equal(isDef ? int.MaxValue : 333, actual.MaxConnectionsPerServer);
Assert.Equal(isDef ? HttpHandlerOptions.DefaultPooledConnectionLifetimeSeconds : 333, actual.PooledConnectionLifeTime.TotalSeconds);
Assert.Equal(!isDef, actual.UseCookieContainer);
Expand All @@ -328,6 +331,7 @@ public void Merge(bool isDef, bool hasTracer)
private static FileHttpHandlerOptions RouteOptions() => new()
{
AllowAutoRedirect = true,
EnableMultipleHttp2Connections = true,
MaxConnectionsPerServer = 333,
PooledConnectionLifetimeSeconds = 333,
UseCookieContainer = true,
Expand All @@ -341,6 +345,7 @@ public void Merge(bool isDef, bool hasTracer)
{
RouteKeys = null,
AllowAutoRedirect = false,
EnableMultipleHttp2Connections = false,
MaxConnectionsPerServer = 111,
PooledConnectionLifetimeSeconds = 111,
UseCookieContainer = false,
Expand Down
Loading