|
|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
+// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
using System;
|
|
|
@@ -9,9 +9,11 @@ using System.Net.Http;
|
|
|
using System.Threading.Tasks;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Http.Endpoints;
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
using Microsoft.AspNetCore.TestHost;
|
|
|
using Microsoft.AspNetCore.Testing.xunit;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
using Xunit;
|
|
|
|
|
|
@@ -72,6 +74,41 @@ namespace Microsoft.AspNetCore.StaticFiles
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public async Task Endpoint_PassesThrough()
|
|
|
+ {
|
|
|
+ using (var fileProvider = new PhysicalFileProvider(Path.Combine(AppContext.BaseDirectory, ".")))
|
|
|
+ {
|
|
|
+ var server = StaticFilesTestServer.Create(
|
|
|
+ app =>
|
|
|
+ {
|
|
|
+ app.Use(next => context =>
|
|
|
+ {
|
|
|
+ // Assign an endpoint, this will make the default files noop.
|
|
|
+ context.SetEndpoint(new Endpoint((c) =>
|
|
|
+ {
|
|
|
+ return context.Response.WriteAsync(context.Request.Path.Value);
|
|
|
+ },
|
|
|
+ new EndpointMetadataCollection(),
|
|
|
+ "test"));
|
|
|
+
|
|
|
+ return next(context);
|
|
|
+ });
|
|
|
+
|
|
|
+ app.UseDefaultFiles(new DefaultFilesOptions
|
|
|
+ {
|
|
|
+ RequestPath = new PathString(""),
|
|
|
+ FileProvider = fileProvider
|
|
|
+ });
|
|
|
+ },
|
|
|
+ services => services.AddDirectoryBrowser());
|
|
|
+
|
|
|
+ var response = await server.CreateRequest("/SubFolder/").GetAsync();
|
|
|
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
+ Assert.Equal("/SubFolder/", await response.Content.ReadAsStringAsync()); // Should not be modified
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Theory]
|
|
|
[InlineData("", @".", "/SubFolder/")]
|
|
|
[InlineData("", @"./", "/SubFolder/")]
|