Skip to content

Commit

Permalink
Add named pipes methods to Kestrel configuration loader (#56563)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Jul 4, 2024
1 parent 8bf9970 commit 75368e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Servers/Kestrel/Core/src/KestrelConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ public KestrelConfigurationLoader UnixSocketEndpoint(string socketPath, Action<L
return this;
}

/// <summary>
/// Bind to given named pipe.
/// </summary>
public KestrelConfigurationLoader NamedPipeEndpoint(string pipeName) => NamedPipeEndpoint(pipeName, _ => { });

/// <summary>
/// Bind to given named pipe.
/// </summary>
public KestrelConfigurationLoader NamedPipeEndpoint(string pipeName, Action<ListenOptions> configure)
{
ArgumentNullException.ThrowIfNull(pipeName);
ArgumentNullException.ThrowIfNull(configure);

EndpointsToAdd.Add(() =>
{
Options.ListenNamedPipe(pipeName, configure);
});

return this;
}

/// <summary>
/// Open a socket file descriptor.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Servers/Kestrel/Core/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.NamedPipeEndpoint(string! pipeName) -> Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader!
Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.NamedPipeEndpoint(string! pipeName, System.Action<Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions!>! configure) -> Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader!
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,23 @@ public void ReloadDoesNotAddEndpoints()
_ = serverOptions.ConfigurationLoader.Reload();
}

[Fact]
public void AddNamedPipeEndpoint()
{
var serverOptions = CreateServerOptions();
var builder = serverOptions.Configure()
.NamedPipeEndpoint("abc");

Assert.Empty(serverOptions.GetListenOptions());
Assert.Equal(builder, serverOptions.ConfigurationLoader);

builder.Load();

Assert.Single(serverOptions.GetListenOptions());
Assert.Equal("abc", serverOptions.CodeBackedListenOptions[0].PipeName);
Assert.NotNull(serverOptions.ConfigurationLoader);
}

private static string GetCertificatePath()
{
var appData = Environment.GetEnvironmentVariable("APPDATA");
Expand Down

0 comments on commit 75368e2

Please sign in to comment.