Skip to content
Merged
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
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