Skip to content

Commit 26139ea

Browse files
committed
Add ServerOptionsSelectionCallback UseHttps overload
1 parent 4797582 commit 26139ea

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/Servers/Kestrel/Core/src/ListenOptionsHttpsExtensions.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Net.Security;
77
using System.Security.Cryptography.X509Certificates;
88
using Microsoft.AspNetCore.Server.Kestrel.Core;
9-
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
109
using Microsoft.AspNetCore.Server.Kestrel.Https;
1110
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
1211
using Microsoft.Extensions.DependencyInjection;
@@ -235,7 +234,37 @@ public static ListenOptions UseHttps(this ListenOptions listenOptions, HttpsConn
235234
/// </summary>
236235
/// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param>
237236
/// <param name="httpsOptionsCallback">Callback to configure HTTPS options.</param>
238-
/// <param name="state">State for the <see cref="ServerOptionsSelectionCallback" />.</param>
237+
/// <param name="state">State for the <paramref name="httpsOptionsCallback"/>.</param>
238+
/// <returns>The <see cref="ListenOptions"/>.</returns>
239+
public static ListenOptions UseHttps(this ListenOptions listenOptions, ServerOptionsSelectionCallback httpsOptionsCallback, object state)
240+
{
241+
return listenOptions.UseHttps(httpsOptionsCallback, state, HttpsConnectionAdapterOptions.DefaultHandshakeTimeout);
242+
}
243+
244+
/// <summary>
245+
/// Configure Kestrel to use HTTPS.
246+
/// </summary>
247+
/// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param>
248+
/// <param name="httpsOptionsCallback">Callback to configure HTTPS options.</param>
249+
/// <param name="state">State for the <paramref name="httpsOptionsCallback"/>.</param>
250+
/// <param name="handshakeTimeout">Specifies the maximum amount of time allowed for the TLS/SSL handshake. This must be positive and finite.</param>
251+
/// <returns>The <see cref="ListenOptions"/>.</returns>
252+
public static ListenOptions UseHttps(this ListenOptions listenOptions, ServerOptionsSelectionCallback httpsOptionsCallback, object state, TimeSpan handshakeTimeout)
253+
{
254+
// HttpsOptionsCallback is an internal delegate that is just the ServerOptionsSelectionCallback + a ConnectionContext parameter.
255+
// Given that ConnectionContext will eventually be replaced by System.Net.Connections, it doesn't make much sense to make the HttpsOptionsCallback delegate public.
256+
HttpsOptionsCallback adaptedCallback = (connection, stream, clientHelloInfo, state, cancellationToken) =>
257+
httpsOptionsCallback(stream, clientHelloInfo, state, cancellationToken);
258+
259+
return listenOptions.UseHttps(adaptedCallback, state, handshakeTimeout);
260+
}
261+
262+
/// <summary>
263+
/// Configure Kestrel to use HTTPS.
264+
/// </summary>
265+
/// <param name="listenOptions">The <see cref="ListenOptions"/> to configure.</param>
266+
/// <param name="httpsOptionsCallback">Callback to configure HTTPS options.</param>
267+
/// <param name="state">State for the <paramref name="httpsOptionsCallback"/>.</param>
239268
/// <param name="handshakeTimeout">Specifies the maximum amount of time allowed for the TLS/SSL handshake. This must be positive and finite.</param>
240269
/// <returns>The <see cref="ListenOptions"/>.</returns>
241270
internal static ListenOptions UseHttps(this ListenOptions listenOptions, HttpsOptionsCallback httpsOptionsCallback, object state, TimeSpan handshakeTimeout)

0 commit comments

Comments
 (0)