Skip to content

Commit

Permalink
Add EnableMultipleHttp2Connections to ProxyHttpClientOptions (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahbazi authored Feb 16, 2021
1 parent 3d5fb29 commit dca5dd7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ public sealed record ProxyHttpClientOptions
/// </summary>
public ActivityContextHeaders? ActivityContextHeaders { get; init; }

// TODO: Add this property once we have migrated to SDK version that supports it.
//public bool? EnableMultipleHttp2Connections { get; init; }
#if NET
/// <summary>
/// Gets or sets a value that indicates whether additional HTTP/2 connections can
// be established to the same server when the maximum number of concurrent streams
// is reached on all existing connections.
/// </summary>
public bool? EnableMultipleHttp2Connections { get; init; }
#endif

/// <inheritdoc />
public bool Equals(ProxyHttpClientOptions other)
Expand All @@ -58,6 +64,9 @@ public bool Equals(ProxyHttpClientOptions other)
&& CertEquals(ClientCertificate, other.ClientCertificate)
&& DangerousAcceptAnyServerCertificate == other.DangerousAcceptAnyServerCertificate
&& MaxConnectionsPerServer == other.MaxConnectionsPerServer
#if NET
&& EnableMultipleHttp2Connections == other.EnableMultipleHttp2Connections
#endif
&& ActivityContextHeaders == other.ActivityContextHeaders;
}

Expand All @@ -83,6 +92,9 @@ public override int GetHashCode()
ClientCertificate?.Thumbprint,
DangerousAcceptAnyServerCertificate,
MaxConnectionsPerServer,
#if NET
EnableMultipleHttp2Connections,
#endif
ActivityContextHeaders);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ReverseProxy/Configuration/ConfigurationConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ private ProxyHttpClientOptions CreateProxyHttpClientOptions(IConfigurationSectio
DangerousAcceptAnyServerCertificate = section.ReadBool(nameof(ProxyHttpClientOptions.DangerousAcceptAnyServerCertificate)),
ClientCertificate = clientCertificate,
MaxConnectionsPerServer = section.ReadInt32(nameof(ProxyHttpClientOptions.MaxConnectionsPerServer)),
#if NET
EnableMultipleHttp2Connections = section.ReadBool(nameof(ProxyHttpClientOptions.EnableMultipleHttp2Connections)),
#endif
ActivityContextHeaders = section.ReadEnum<ActivityContextHeaders>(nameof(ProxyHttpClientOptions.ActivityContextHeaders))
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public HttpMessageInvoker CreateClient(ProxyHttpClientContext context)
{
handler.SslOptions.RemoteCertificateValidationCallback = delegate { return true; };
}
#if NET
if (newClientOptions.EnableMultipleHttp2Connections.HasValue)
{
handler.EnableMultipleHttp2Connections = newClientOptions.EnableMultipleHttp2Connections.Value;
}
#endif

Log.ProxyClientCreated(_logger, context.ClusterId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public class ConfigurationConfigProviderTests
SslProtocols = SslProtocols.Tls11 | SslProtocols.Tls12,
MaxConnectionsPerServer = 10,
DangerousAcceptAnyServerCertificate = true,
ActivityContextHeaders = ActivityContextHeaders.Baggage
ActivityContextHeaders = ActivityContextHeaders.Baggage,
#if NET
EnableMultipleHttp2Connections = true,
#endif
},
HttpRequest = new RequestProxyOptions()
{
Expand Down Expand Up @@ -213,7 +216,7 @@ public class ConfigurationConfigProviderTests
""AllowInvalid"": null
},
""MaxConnectionsPerServer"": 10,
""PropagateActivityContext"": true,
""EnableMultipleHttp2Connections"": true,
""ActivityContextHeaders"": ""Baggage""
},
""HttpRequest"": {
Expand Down Expand Up @@ -596,6 +599,9 @@ private void VerifyValidAbstractConfig(IProxyConfig validConfig, X509Certificate
Assert.Equal(cluster1.SessionAffinity.Settings, abstractCluster1.SessionAffinity.Settings);
Assert.Same(certificate, abstractCluster1.HttpClient.ClientCertificate);
Assert.Equal(cluster1.HttpClient.MaxConnectionsPerServer, abstractCluster1.HttpClient.MaxConnectionsPerServer);
#if NET
Assert.Equal(cluster1.HttpClient.EnableMultipleHttp2Connections, abstractCluster1.HttpClient.EnableMultipleHttp2Connections);
#endif
Assert.Equal(cluster1.HttpClient.ActivityContextHeaders, abstractCluster1.HttpClient.ActivityContextHeaders);
Assert.Equal(SslProtocols.Tls11 | SslProtocols.Tls12, abstractCluster1.HttpClient.SslProtocols);
Assert.Equal(cluster1.HttpRequest.Timeout, abstractCluster1.HttpRequest.Timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void CreateClient_ApplySslProtocols_Success()
var factory = new ProxyHttpClientFactory(Mock<ILogger<ProxyHttpClientFactory>>().Object);
var options = new ProxyHttpClientOptions
{
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
};
var client = factory.CreateClient(new ProxyHttpClientContext { NewOptions = options });

Expand Down Expand Up @@ -145,6 +145,22 @@ public void CreateClient_OldClientExistsNoConfigChange_ReturnsOldInstance()
Assert.Same(oldClient, actualClient);
}

#if NET
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CreateClient_ApplyEnableMultipleHttp2Connections_Success(bool enableMultipleHttp2Connections)
{
var factory = new ProxyHttpClientFactory(Mock<ILogger<ProxyHttpClientFactory>>().Object);
var options = new ProxyHttpClientOptions { EnableMultipleHttp2Connections = enableMultipleHttp2Connections };
var client = factory.CreateClient(new ProxyHttpClientContext { NewOptions = options });

var handler = GetHandler(client);

Assert.Equal(enableMultipleHttp2Connections, handler.EnableMultipleHttp2Connections);
}
#endif

[Theory]
[MemberData(nameof(GetChangedHttpClientOptions))]
public void CreateClient_OldClientExistsHttpClientOptionsChanged_ReturnsNewInstance(ProxyHttpClientOptions oldOptions, ProxyHttpClientOptions newOptions)
Expand Down Expand Up @@ -343,7 +359,29 @@ public static IEnumerable<object[]> GetChangedHttpClientOptions()
MaxConnectionsPerServer = 10,
ActivityContextHeaders = ActivityContextHeaders.BaggageAndCorrelationContext,
},
},
#if NET
new object[] {
new ProxyHttpClientOptions
{
SslProtocols = SslProtocols.Tls11,
DangerousAcceptAnyServerCertificate = true,
ClientCertificate = null,
MaxConnectionsPerServer = 10,
ActivityContextHeaders = ActivityContextHeaders.Baggage,
EnableMultipleHttp2Connections = true
},
new ProxyHttpClientOptions
{
SslProtocols = SslProtocols.Tls11,
DangerousAcceptAnyServerCertificate = true,
ClientCertificate = null,
MaxConnectionsPerServer = 10,
ActivityContextHeaders = ActivityContextHeaders.Baggage,
EnableMultipleHttp2Connections = false
},
}
#endif
};
}

Expand Down

0 comments on commit dca5dd7

Please sign in to comment.