Handle IFileSystem rename.

This commit is contained in:
Chris Ross 2015-01-20 08:58:41 -08:00
parent 60c3e7e971
commit 96835bd761
14 changed files with 53 additions and 53 deletions

View File

@ -1,5 +1,5 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.StaticFiles;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Logging.Console;

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.StaticFiles
/// <param name="options">The configuration options for this middleware.</param>
public DefaultFilesMiddleware([NotNull] RequestDelegate next, [NotNull] IHostingEnvironment hostingEnv, [NotNull] DefaultFilesOptions options)
{
options.ResolveFileSystem(hostingEnv);
options.ResolveFileProvider(hostingEnv);
_next = next;
_options = options;
@ -47,14 +47,14 @@ namespace Microsoft.AspNet.StaticFiles
if (Helpers.IsGetOrHeadMethod(context.Request.Method)
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out subpath))
{
var dirContents = _options.FileSystem.GetDirectoryContents(subpath.Value);
var dirContents = _options.FileProvider.GetDirectoryContents(subpath.Value);
if (dirContents.Exists)
{
// Check if any of our default files exist.
for (int matchIndex = 0; matchIndex < _options.DefaultFileNames.Count; matchIndex++)
{
string defaultFile = _options.DefaultFileNames[matchIndex];
var file = _options.FileSystem.GetFileInfo(subpath + defaultFile);
var file = _options.FileProvider.GetFileInfo(subpath + defaultFile);
// TryMatchPath will make sure subpath always ends with a "/" by adding it if needed.
if (file.Exists)
{

View File

@ -4,7 +4,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Net.Http.Headers;
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.StaticFiles
{
throw new ArgumentException(Resources.Args_NoFormatter);
}
options.ResolveFileSystem(hostingEnv);
options.ResolveFileProvider(hostingEnv);
_next = next;
_options = options;
@ -69,7 +69,7 @@ namespace Microsoft.AspNet.StaticFiles
private bool TryGetDirectoryInfo(PathString subpath, out IDirectoryContents contents)
{
contents = _options.FileSystem.GetDirectoryContents(subpath.Value);
contents = _options.FileProvider.GetDirectoryContents(subpath.Value);
return contents.Exists;
}
}

View File

@ -8,7 +8,7 @@ using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.StaticFiles

View File

@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.StaticFiles

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.StaticFiles.Infrastructure
@ -41,6 +41,6 @@ namespace Microsoft.AspNet.StaticFiles.Infrastructure
/// <summary>
/// The file system used to locate resources
/// </summary>
public IFileSystem FileSystem { get; set; }
public IFileProvider FileProvider { get; set; }
}
}

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
@ -45,20 +45,20 @@ namespace Microsoft.AspNet.StaticFiles.Infrastructure
/// <summary>
/// The file system used to locate resources
/// </summary>
public IFileSystem FileSystem
public IFileProvider FileProvider
{
get { return SharedOptions.FileSystem; }
set { SharedOptions.FileSystem = value; }
get { return SharedOptions.FileProvider; }
set { SharedOptions.FileProvider = value; }
}
internal void ResolveFileSystem(IHostingEnvironment hostingEnv)
internal void ResolveFileProvider(IHostingEnvironment hostingEnv)
{
if (FileSystem == null)
if (FileProvider == null)
{
FileSystem = hostingEnv.WebRootFileSystem;
if (FileSystem == null)
FileProvider = hostingEnv.WebRootFileProvider;
if (FileProvider == null)
{
throw new InvalidOperationException("Missing FileSystem.");
throw new InvalidOperationException("Missing FileProvider.");
}
}
}

View File

@ -7,7 +7,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Headers;
using Microsoft.AspNet.Http.Interfaces;
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.StaticFiles
public bool LookupFileInfo()
{
_fileInfo = _options.FileSystem.GetFileInfo(_subPath.Value);
_fileInfo = _options.FileProvider.GetFileInfo(_subPath.Value);
if (_fileInfo.Exists)
{
_length = _fileInfo.Length;

View File

@ -4,7 +4,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Logging;
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.StaticFiles
{
throw new ArgumentException(Resources.Args_NoContentTypeProvider);
}
options.ResolveFileSystem(hostingEnv);
options.ResolveFileProvider(hostingEnv);
_next = next;
_options = options;

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.StaticFiles

View File

@ -7,7 +7,7 @@ using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.TestHost;
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.StaticFiles
public async Task NullArguments()
{
// No exception, default provided
TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions() { FileSystem = null }));
TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions() { FileProvider = null }));
// PathString(null) is OK.
TestServer server = TestServer.Create(app => app.UseDefaultFiles((string)null));
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.StaticFiles
app.UseDefaultFiles(new DefaultFilesOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
});
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
});
@ -63,7 +63,7 @@ namespace Microsoft.AspNet.StaticFiles
app.UseDefaultFiles(new DefaultFilesOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
});
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
});
@ -81,11 +81,11 @@ namespace Microsoft.AspNet.StaticFiles
{
TestServer server = TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
RequestPath = new PathString(baseUrl),
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl + queryString).GetAsync();
Assert.Equal(HttpStatusCode.Moved, response.StatusCode);
Assert.Equal(requestUrl + "/" + queryString, response.Headers.Location.ToString());
Assert.Equal(0, (await response.Content.ReadAsByteArrayAsync()).Length);
@ -101,7 +101,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseDefaultFiles(new DefaultFilesOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();

View File

@ -7,7 +7,7 @@ using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.TestHost;
using Xunit;
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.StaticFiles
Assert.Throws<ArgumentException>(() => TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions() { Formatter = null })));
// No exception, default provided
TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions() { FileSystem = null }));
TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions() { FileProvider = null }));
// PathString(null) is OK.
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser((string)null));
@ -40,8 +40,8 @@ namespace Microsoft.AspNet.StaticFiles
{
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
RequestPath = new PathString(baseUrl),
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl + queryString).GetAsync();
@ -99,7 +99,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).PostAsync();
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@ -115,7 +115,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseDirectoryBrowser(new DirectoryBrowserOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).SendAsync("HEAD");

View File

@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.Framework.Expiration.Interfaces;
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.StaticFiles
{
// Arrange
var options = new StaticFileOptions();
options.FileSystem = new TestFileSystem();
options.FileProvider = new TestFileProvider();
var context = new StaticFileContext(new DefaultHttpContext(), options, PathString.Empty, NullLogger.Instance);
// Act
@ -37,12 +37,12 @@ namespace Microsoft.AspNet.StaticFiles
{
// Arrange
var options = new StaticFileOptions();
var fileSystem = new TestFileSystem();
fileSystem.AddFile("/foo.txt", new TestFileInfo
var fileProvider = new TestFileProvider();
fileProvider.AddFile("/foo.txt", new TestFileInfo
{
LastModified = new DateTimeOffset(2014, 1, 2, 3, 4, 5, TimeSpan.Zero)
});
options.FileSystem = fileSystem;
options.FileProvider = fileProvider;
var pathString = new PathString("/test");
var httpContext = new DefaultHttpContext();
httpContext.Request.Path = new PathString("/test/foo.txt");
@ -56,7 +56,7 @@ namespace Microsoft.AspNet.StaticFiles
Assert.True(result);
}
private sealed class TestFileSystem : IFileSystem
private sealed class TestFileProvider : IFileProvider
{
private readonly Dictionary<string, IFileInfo> _files = new Dictionary<string, IFileInfo>(StringComparer.Ordinal);

View File

@ -7,7 +7,7 @@ using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.TestHost;
using Xunit;
@ -22,7 +22,7 @@ namespace Microsoft.AspNet.StaticFiles
Assert.Throws<ArgumentException>(() => TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = null })));
// No exception, default provided
TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions() { FileSystem = null }));
TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions() { FileProvider = null }));
// PathString(null) is OK.
TestServer server = TestServer.Create(app => app.UseStaticFiles((string)null));
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).GetAsync();
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).PostAsync();
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
@ -98,7 +98,7 @@ namespace Microsoft.AspNet.StaticFiles
TestServer server = TestServer.Create(app => app.UseStaticFiles(new StaticFileOptions()
{
RequestPath = new PathString(baseUrl),
FileSystem = new PhysicalFileSystem(Path.Combine(Environment.CurrentDirectory, baseDir))
FileProvider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, baseDir))
}));
HttpResponseMessage response = await server.CreateRequest(requestUrl).SendAsync("HEAD");