From 4333003df0c5f2ad0a1dc3047fd2a5ae862a6c16 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Thu, 18 Dec 2014 15:30:43 -0800 Subject: [PATCH] Generalize BasePath logic. --- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 6 ++++++ src/Microsoft.AspNet.TestHost/TestServer.cs | 5 ----- test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index b23dffbe70..d108874bdd 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -38,6 +38,12 @@ namespace Microsoft.AspNet.TestHost } _next = next; + + // PathString.StartsWithSegments that we use below requires the base path to not end in a slash. + if (pathBase.HasValue && pathBase.Value.EndsWith("/")) + { + pathBase = new PathString(pathBase.Value.Substring(0, pathBase.Value.Length - 1)); + } _pathBase = pathBase; } diff --git a/src/Microsoft.AspNet.TestHost/TestServer.cs b/src/Microsoft.AspNet.TestHost/TestServer.cs index 97e848033a..54b908133e 100644 --- a/src/Microsoft.AspNet.TestHost/TestServer.cs +++ b/src/Microsoft.AspNet.TestHost/TestServer.cs @@ -62,11 +62,6 @@ namespace Microsoft.AspNet.TestHost public HttpMessageHandler CreateHandler() { var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress); - if (pathBase.Equals(new PathString("/"))) - { - // When we just have http://host/ the trailing slash is really part of the Path, not the PathBase. - pathBase = PathString.Empty; - } return new ClientHandler(Invoke, pathBase); } diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index 23f65bce8b..a536114e57 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.TestHost Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0); - }, new PathString("/A/Path")); + }, new PathString("/A/Path/")); var httpClient = new HttpClient(handler); return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query"); }