Skip to content

Commit 9dc1ec6

Browse files
committed
Longest match test
1 parent 8bab6b5 commit 9dc1ec6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Servers/HttpSys/src/UrlPrefixCollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ internal bool TryMatchLongestPrefix(bool isHttps, string host, string originalPa
7373
{
7474
foreach (var prefix in _prefixes.Values)
7575
{
76+
// The scheme, host, port, and start of path must match.
77+
// Note this does not currently handle prefixes with wildcard subdomains.
7678
if (isHttps == prefix.IsHttps
7779
&& string.Equals(host, prefix.HostAndPort, StringComparison.OrdinalIgnoreCase)
7880
&& originalPathString.StartsWithSegments(new PathString(prefix.PathWithoutTrailingSlash), StringComparison.OrdinalIgnoreCase, out var remainder)

src/Servers/HttpSys/test/FunctionalTests/Listener/ServerOnExistingQueueTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ public async Task Server_PathSplitting(string pathBase, string requestPath, stri
144144
Assert.Equal(string.Empty, response);
145145
}
146146

147+
[ConditionalFact]
148+
public async Task Server_LongestPathSplitting()
149+
{
150+
using var baseServer = Utilities.CreateDynamicHttpServer("/basepath", out var root, out var baseAddress);
151+
baseServer.Options.UrlPrefixes.Add(baseAddress + "secondTier");
152+
using var server = Utilities.CreateServerOnExistingQueue(baseServer.Options.RequestQueueName);
153+
server.Options.UrlPrefixes.Add(baseAddress); // Keep them in sync
154+
server.Options.UrlPrefixes.Add(baseAddress + "secondTier");
155+
156+
var responseTask = SendRequestAsync(root + "/basepath/secondTier/path/thing");
157+
158+
var context = await server.AcceptAsync(Utilities.DefaultTimeout).Before(responseTask);
159+
Assert.Equal("/basepath/secondTier", context.Request.PathBase);
160+
Assert.Equal("/path/thing", context.Request.Path);
161+
context.Dispose();
162+
163+
var response = await responseTask;
164+
Assert.Equal(string.Empty, response);
165+
}
166+
147167
[ConditionalFact]
148168
// Changes to the base server are reflected
149169
public async Task Server_HotAddPrefix_Success()

0 commit comments

Comments
 (0)