Skip to content

Commit 75368e2

Browse files
authored
Add named pipes methods to Kestrel configuration loader (#56563)
1 parent 8bf9970 commit 75368e2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/Servers/Kestrel/Core/src/KestrelConfigurationLoader.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ public KestrelConfigurationLoader UnixSocketEndpoint(string socketPath, Action<L
191191
return this;
192192
}
193193

194+
/// <summary>
195+
/// Bind to given named pipe.
196+
/// </summary>
197+
public KestrelConfigurationLoader NamedPipeEndpoint(string pipeName) => NamedPipeEndpoint(pipeName, _ => { });
198+
199+
/// <summary>
200+
/// Bind to given named pipe.
201+
/// </summary>
202+
public KestrelConfigurationLoader NamedPipeEndpoint(string pipeName, Action<ListenOptions> configure)
203+
{
204+
ArgumentNullException.ThrowIfNull(pipeName);
205+
ArgumentNullException.ThrowIfNull(configure);
206+
207+
EndpointsToAdd.Add(() =>
208+
{
209+
Options.ListenNamedPipe(pipeName, configure);
210+
});
211+
212+
return this;
213+
}
214+
194215
/// <summary>
195216
/// Open a socket file descriptor.
196217
/// </summary>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.NamedPipeEndpoint(string! pipeName) -> Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader!
3+
Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.NamedPipeEndpoint(string! pipeName, System.Action<Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions!>! configure) -> Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader!

src/Servers/Kestrel/Kestrel/test/KestrelConfigurationLoaderTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,23 @@ public void ReloadDoesNotAddEndpoints()
18441844
_ = serverOptions.ConfigurationLoader.Reload();
18451845
}
18461846

1847+
[Fact]
1848+
public void AddNamedPipeEndpoint()
1849+
{
1850+
var serverOptions = CreateServerOptions();
1851+
var builder = serverOptions.Configure()
1852+
.NamedPipeEndpoint("abc");
1853+
1854+
Assert.Empty(serverOptions.GetListenOptions());
1855+
Assert.Equal(builder, serverOptions.ConfigurationLoader);
1856+
1857+
builder.Load();
1858+
1859+
Assert.Single(serverOptions.GetListenOptions());
1860+
Assert.Equal("abc", serverOptions.CodeBackedListenOptions[0].PipeName);
1861+
Assert.NotNull(serverOptions.ConfigurationLoader);
1862+
}
1863+
18471864
private static string GetCertificatePath()
18481865
{
18491866
var appData = Environment.GetEnvironmentVariable("APPDATA");

0 commit comments

Comments
 (0)