Fix issue with empty path.
This commit is contained in:
parent
bf5d14f477
commit
b7bb7f8fcf
|
|
@ -72,6 +72,11 @@ 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,21 @@ namespace Microsoft.AspNet.TestHost
|
|||
return httpClient.GetAsync("https://example.com/A/Path/and/file.txt?and=query");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task SingleSlashNotMovedToPathBase()
|
||||
{
|
||||
var handler = new ClientHandler(env =>
|
||||
{
|
||||
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||
Assert.Equal("", context.Request.PathBase.Value);
|
||||
Assert.Equal("/", context.Request.Path.Value);
|
||||
|
||||
return Task.FromResult(0);
|
||||
}, new PathString(""));
|
||||
var httpClient = new HttpClient(handler);
|
||||
return httpClient.GetAsync("https://example.com/");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResubmitRequestWorks()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,48 @@ namespace Microsoft.AspNet.TestHost
|
|||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NoTrailingSlash_NoPathBase()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "GET Response";
|
||||
RequestDelegate appDelegate = ctx =>
|
||||
{
|
||||
Assert.Equal("", ctx.Request.PathBase.Value);
|
||||
Assert.Equal("/", ctx.Request.Path.Value);
|
||||
return ctx.Response.WriteAsync(expected);
|
||||
};
|
||||
var server = TestServer.Create(_services, app => app.Run(appDelegate));
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var actual = await client.GetStringAsync("http://localhost:12345");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SingleTrailingSlash_NoPathBase()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "GET Response";
|
||||
RequestDelegate appDelegate = ctx =>
|
||||
{
|
||||
Assert.Equal("", ctx.Request.PathBase.Value);
|
||||
Assert.Equal("/", ctx.Request.Path.Value);
|
||||
return ctx.Response.WriteAsync(expected);
|
||||
};
|
||||
var server = TestServer.Create(_services, app => app.Run(appDelegate));
|
||||
var client = server.CreateClient();
|
||||
|
||||
// Act
|
||||
var actual = await client.GetStringAsync("http://localhost:12345/");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PutAsyncWorks()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue