Skip to content

Commit e034973

Browse files
committed
PR feedback
1 parent 0b03961 commit e034973

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

src/Http/Http/src/BindingAddress.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Http;
1111
public class BindingAddress
1212
{
1313
private const string UnixPipeHostPrefix = "unix:/";
14-
private const string NamedPipeHostPrefix = "pipe:";
14+
private const string NamedPipeHostPrefix = "pipe:/";
1515

1616
private BindingAddress(string host, string pathBase, int port, string scheme)
1717
{
@@ -61,7 +61,7 @@ public BindingAddress()
6161
/// <summary>
6262
/// Gets a value that determines if this instance represents a named pipe.
6363
/// <para>
64-
/// Returns <see langword="true"/> if <see cref="Host"/> starts with <c>pipe:</c> prefix.
64+
/// Returns <see langword="true"/> if <see cref="Host"/> starts with <c>pipe:/</c> prefix.
6565
/// </para>
6666
/// </summary>
6767
public bool IsNamedPipe => Host.StartsWith(NamedPipeHostPrefix, StringComparison.Ordinal);
@@ -83,9 +83,9 @@ public string UnixPipePath
8383
}
8484

8585
/// <summary>
86-
/// Gets the named pipe path if this instance represents a named pipe.
86+
/// Gets the named pipe name if this instance represents a named pipe.
8787
/// </summary>
88-
public string NamedPipePath
88+
public string NamedPipeName
8989
{
9090
get
9191
{
@@ -94,7 +94,7 @@ public string NamedPipePath
9494
throw new InvalidOperationException("Binding address is not a named pipe.");
9595
}
9696

97-
return GetNamedPipePath(Host);
97+
return GetNamedPipeName(Host);
9898
}
9999
}
100100

@@ -109,7 +109,7 @@ private static string GetUnixPipePath(string host)
109109
return host.Substring(unixPipeHostPrefixLength);
110110
}
111111

112-
private static string GetNamedPipePath(string host) => host.Substring(NamedPipeHostPrefix.Length);
112+
private static string GetNamedPipeName(string host) => host.Substring(NamedPipeHostPrefix.Length);
113113

114114
/// <inheritdoc />
115115
public override string ToString()
@@ -248,11 +248,6 @@ public static BindingAddress Parse(string address)
248248
throw new FormatException($"Invalid url, unix socket path must be absolute: '{address}'");
249249
}
250250

251-
if (isNamedPipe && GetNamedPipePath(host).Contains('\\'))
252-
{
253-
throw new FormatException($"Invalid url, pipe name must not contain backslashes: '{address}'");
254-
}
255-
256251
string pathBase;
257252
if (address[address.Length - 1] == '/')
258253
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#nullable enable
22
*REMOVED*Microsoft.AspNetCore.Http.StreamResponseBodyFeature.StreamResponseBodyFeature(System.IO.Stream! stream, Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature! priorFeature) -> void
33
Microsoft.AspNetCore.Http.BindingAddress.IsNamedPipe.get -> bool
4-
Microsoft.AspNetCore.Http.BindingAddress.NamedPipePath.get -> string!
4+
Microsoft.AspNetCore.Http.BindingAddress.NamedPipeName.get -> string!
55
Microsoft.AspNetCore.Http.StreamResponseBodyFeature.StreamResponseBodyFeature(System.IO.Stream! stream, Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature? priorFeature) -> void

src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ internal static ListenOptions ParseAddress(string address, out bool https)
122122
}
123123
else if (parsedAddress.IsNamedPipe)
124124
{
125-
options = new ListenOptions(new NamedPipeEndPoint(parsedAddress.NamedPipePath));
125+
options = new ListenOptions(new NamedPipeEndPoint(parsedAddress.NamedPipeName));
126126
}
127127
else if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase))
128128
{

src/Servers/Kestrel/Core/test/AddressBinderTests.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,40 @@ public void ParseAddressLocalhost()
7878
Assert.False(https);
7979
}
8080

81+
[Fact]
82+
public void ParseAddress_HasPipeNoSlash()
83+
{
84+
var listenOptions = AddressBinder.ParseAddress("http://pipe:8080", out var https);
85+
Assert.IsType<IPEndPoint>(listenOptions.EndPoint);
86+
Assert.Equal(8080, listenOptions.IPEndPoint.Port);
87+
Assert.False(https);
88+
}
89+
8190
[Fact]
8291
public void ParseAddressNamedPipe()
8392
{
84-
var listenOptions = AddressBinder.ParseAddress("http://pipe:HelloWorld", out var https);
93+
var listenOptions = AddressBinder.ParseAddress("http://pipe:/HelloWorld", out var https);
8594
Assert.IsType<NamedPipeEndPoint>(listenOptions.EndPoint);
8695
Assert.Equal("HelloWorld", listenOptions.PipeName);
8796
Assert.False(https);
8897
}
8998

9099
[Fact]
91-
public void ParseAddressNamedPipe_ForwardSlashes()
100+
public void ParseAddressNamedPipe_BackSlashes()
92101
{
93-
var listenOptions = AddressBinder.ParseAddress("http://pipe:/tmp/kestrel-test.sock", out var https);
102+
var listenOptions = AddressBinder.ParseAddress(@"http://pipe:/LOCAL\HelloWorld", out var https);
94103
Assert.IsType<NamedPipeEndPoint>(listenOptions.EndPoint);
95-
Assert.Equal("/tmp/kestrel-test.sock", listenOptions.PipeName);
104+
Assert.Equal(@"LOCAL\HelloWorld", listenOptions.PipeName);
96105
Assert.False(https);
97106
}
98107

99108
[Fact]
100-
public void ParseAddressNamedPipe_ErrorFromBackslash()
109+
public void ParseAddressNamedPipe_ForwardSlashes()
101110
{
102-
var ex = Assert.Throws<FormatException>(() => AddressBinder.ParseAddress(@"http://pipe:this\is\invalid", out var https));
103-
Assert.Equal(@"Invalid url, pipe name must not contain backslashes: 'http://pipe:this\is\invalid'", ex.Message);
111+
var listenOptions = AddressBinder.ParseAddress("http://pipe://tmp/kestrel-test.sock", out var https);
112+
Assert.IsType<NamedPipeEndPoint>(listenOptions.EndPoint);
113+
Assert.Equal("/tmp/kestrel-test.sock", listenOptions.PipeName);
114+
Assert.False(https);
104115
}
105116

106117
[ConditionalFact]

0 commit comments

Comments
 (0)