diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index be830c9..8c5a8d8 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -25,13 +25,13 @@ jobs:
runs-on: ubuntu-latest
env:
- Solution_File: Smidge.sln
+ Solution_File: Smidge.slnx
Test_Proj: test/Smidge.Tests/Smidge.Tests.csproj
Configuration: Release
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
with:
fetch-depth: 0
@@ -42,11 +42,10 @@ jobs:
shell: pwsh
- name: Setup .NET Core SDK
- uses: actions/setup-dotnet@v3
+ uses: actions/setup-dotnet@v4
with:
dotnet-version: |
- 6.0.x
- 8.0.x
+ 10.0.x
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.0.3
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..02c2493
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,8 @@
+
+
+
+
+ true
+
+
+
diff --git a/Smidge.sln b/Smidge.sln
deleted file mode 100644
index eb6c750..0000000
--- a/Smidge.sln
+++ /dev/null
@@ -1,73 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.12.35209.166
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A5154E3B-762A-4720-A947-C7A3EA25835A}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{46C13455-622B-44B6-A129-F96EADAD24C8}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{92DBA67A-D9B9-4867-9519-DD846F47ED5C}"
- ProjectSection(SolutionItems) = preProject
- .editorconfig = .editorconfig
- .gitignore = .gitignore
- .github\workflows\build.yml = .github\workflows\build.yml
- src\Directory.Build.props = src\Directory.Build.props
- LICENSE = LICENSE
- GitVersion.yml.bak = GitVersion.yml.bak
- Nuget.config = Nuget.config
- README.md = README.md
- .github\workflows\test-report.yml = .github\workflows\test-report.yml
- EndProjectSection
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Smidge", "src\Smidge\Smidge.csproj", "{C304B5B8-0750-4B60-B6D0-06208639D560}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Smidge.Tests", "test\Smidge.Tests\Smidge.Tests.csproj", "{8C286364-9589-4B52-818E-657A9B12C172}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Smidge.Web", "src\Smidge.Web\Smidge.Web.csproj", "{89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Smidge.InMemory", "src\Smidge.InMemory\Smidge.InMemory.csproj", "{96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Smidge.Core", "src\Smidge.Core\Smidge.Core.csproj", "{B19C5049-69BA-4581-918F-6C2B4961E326}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {C304B5B8-0750-4B60-B6D0-06208639D560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C304B5B8-0750-4B60-B6D0-06208639D560}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C304B5B8-0750-4B60-B6D0-06208639D560}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C304B5B8-0750-4B60-B6D0-06208639D560}.Release|Any CPU.Build.0 = Release|Any CPU
- {8C286364-9589-4B52-818E-657A9B12C172}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8C286364-9589-4B52-818E-657A9B12C172}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8C286364-9589-4B52-818E-657A9B12C172}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8C286364-9589-4B52-818E-657A9B12C172}.Release|Any CPU.Build.0 = Release|Any CPU
- {89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7}.Release|Any CPU.Build.0 = Release|Any CPU
- {96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF}.Release|Any CPU.Build.0 = Release|Any CPU
- {B19C5049-69BA-4581-918F-6C2B4961E326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B19C5049-69BA-4581-918F-6C2B4961E326}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B19C5049-69BA-4581-918F-6C2B4961E326}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B19C5049-69BA-4581-918F-6C2B4961E326}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {C304B5B8-0750-4B60-B6D0-06208639D560} = {A5154E3B-762A-4720-A947-C7A3EA25835A}
- {8C286364-9589-4B52-818E-657A9B12C172} = {46C13455-622B-44B6-A129-F96EADAD24C8}
- {89D8D7E5-4145-4A7E-A41A-EEDCB5FA7AE7} = {A5154E3B-762A-4720-A947-C7A3EA25835A}
- {96EF3FF6-BD73-4495-B9C7-2A6C1C7B50CF} = {A5154E3B-762A-4720-A947-C7A3EA25835A}
- {B19C5049-69BA-4581-918F-6C2B4961E326} = {A5154E3B-762A-4720-A947-C7A3EA25835A}
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {A0EB5714-BE56-4F17-B40A-8E8FADFDF503}
- EndGlobalSection
-EndGlobal
diff --git a/Smidge.slnx b/Smidge.slnx
new file mode 100644
index 0000000..6656e68
--- /dev/null
+++ b/Smidge.slnx
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index de80c4d..5fb5ce4 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -1,12 +1,15 @@
+
+
+
https://github.com/Shazwazza/Smidge
true
true
snupkg
- 9.0
+ latest
@@ -23,6 +26,6 @@
5.0.0
- net8.0;net6.0;
+ net10.0
diff --git a/src/Smidge.Core/Cache/ICacheFileSystem.cs b/src/Smidge.Core/Cache/ICacheFileSystem.cs
index d0527d5..d48f5a5 100644
--- a/src/Smidge.Core/Cache/ICacheFileSystem.cs
+++ b/src/Smidge.Core/Cache/ICacheFileSystem.cs
@@ -12,7 +12,23 @@ namespace Smidge.Cache
///
public interface ICacheFileSystem
{
+ ///
+ /// Gets the for a cached file, throwing a if it does not exist.
+ ///
+ ///
+ /// Use this only when the file is expected to exist as an internal invariant. For request handling where the
+ /// path is (or can be) client supplied, use and check
+ /// so that a missing/stale/spoofed file results in a graceful 404 instead of an unhandled 500.
+ ///
IFileInfo GetRequiredFileInfo(string filePath);
+
+ ///
+ /// Gets the for a cached file without throwing when it does not exist.
+ ///
+ ///
+ /// The returned may have set to false; callers must check it.
+ ///
+ IFileInfo GetFileInfo(string filePath);
Task ClearCachedCompositeFileAsync(string cacheBusterValue, CompressionType type, string filesetKey);
IFileInfo GetCachedCompositeFile(string cacheBusterValue, CompressionType type, string filesetKey, out string filePath);
IFileInfo GetCacheFile(IWebFile file, Func sourceFile, bool fileWatchEnabled, string extension, string cacheBusterValue, out string filePath);
diff --git a/src/Smidge.Core/Cache/PhysicalFileCacheFileSystem.cs b/src/Smidge.Core/Cache/PhysicalFileCacheFileSystem.cs
index e568ae6..99bc61e 100644
--- a/src/Smidge.Core/Cache/PhysicalFileCacheFileSystem.cs
+++ b/src/Smidge.Core/Cache/PhysicalFileCacheFileSystem.cs
@@ -48,6 +48,8 @@ public IFileInfo GetRequiredFileInfo(string filePath)
return fileInfo;
}
+ public IFileInfo GetFileInfo(string filePath) => _fileProvider.GetFileInfo(filePath);
+
private string GetCompositeFilePath(string cacheBusterValue, CompressionType type, string filesetKey) => $"{cacheBusterValue}/{type}/{filesetKey}.s";
public Task ClearCachedCompositeFileAsync(string cacheBusterValue, CompressionType type, string filesetKey)
diff --git a/src/Smidge/NoopSmidgeRequire.cs b/src/Smidge.Core/NoopSmidgeRequire.cs
similarity index 100%
rename from src/Smidge/NoopSmidgeRequire.cs
rename to src/Smidge.Core/NoopSmidgeRequire.cs
diff --git a/src/Smidge.Core/Smidge.Core.csproj b/src/Smidge.Core/Smidge.Core.csproj
index 3216bf0..a1f2df9 100644
--- a/src/Smidge.Core/Smidge.Core.csproj
+++ b/src/Smidge.Core/Smidge.Core.csproj
@@ -13,20 +13,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/src/Smidge/SmidgeRequire.cs b/src/Smidge.Core/SmidgeRequire.cs
similarity index 97%
rename from src/Smidge/SmidgeRequire.cs
rename to src/Smidge.Core/SmidgeRequire.cs
index dc063ea..041a44e 100644
--- a/src/Smidge/SmidgeRequire.cs
+++ b/src/Smidge.Core/SmidgeRequire.cs
@@ -1,7 +1,10 @@
using System;
using System.Linq;
+using System.Runtime.CompilerServices;
using Smidge.Models;
+[assembly: InternalsVisibleTo("Smidge")]
+
namespace Smidge
{
internal class SmidgeRequire : ISmidgeRequire
diff --git a/src/Smidge.InMemory/ConfiguredCacheFileSystem.cs b/src/Smidge.InMemory/ConfiguredCacheFileSystem.cs
index 219b220..91aaa5c 100644
--- a/src/Smidge.InMemory/ConfiguredCacheFileSystem.cs
+++ b/src/Smidge.InMemory/ConfiguredCacheFileSystem.cs
@@ -54,6 +54,9 @@ public IFileInfo GetCacheFile(IWebFile file, Func sourceFile, bool fi
public IFileInfo GetRequiredFileInfo(string filePath)
=> _wrapped.GetRequiredFileInfo(filePath);
+ public IFileInfo GetFileInfo(string filePath)
+ => _wrapped.GetFileInfo(filePath);
+
public Task WriteFileAsync(string filePath, string contents)
=> _wrapped.WriteFileAsync(filePath, contents);
diff --git a/src/Smidge.InMemory/MemoryCacheFileSystem.cs b/src/Smidge.InMemory/MemoryCacheFileSystem.cs
index 38783f2..3b67086 100644
--- a/src/Smidge.InMemory/MemoryCacheFileSystem.cs
+++ b/src/Smidge.InMemory/MemoryCacheFileSystem.cs
@@ -37,6 +37,8 @@ public IFileInfo GetRequiredFileInfo(string filePath)
return fileInfo;
}
+ public IFileInfo GetFileInfo(string filePath) => _fileProvider.GetFileInfo(filePath);
+
private string GetCompositeFilePath(string cacheBusterValue, CompressionType type, string filesetKey)
=> $"{cacheBusterValue}/{type}/{filesetKey + ".s"}";
diff --git a/src/Smidge.InMemory/Smidge.InMemory.csproj b/src/Smidge.InMemory/Smidge.InMemory.csproj
index d962659..9b76e0d 100644
--- a/src/Smidge.InMemory/Smidge.InMemory.csproj
+++ b/src/Smidge.InMemory/Smidge.InMemory.csproj
@@ -12,15 +12,6 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/Smidge.Web/Startup.cs b/src/Smidge.Web/Startup.cs
index 10fa848..ab470ab 100644
--- a/src/Smidge.Web/Startup.cs
+++ b/src/Smidge.Web/Startup.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
-using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@@ -48,10 +47,10 @@ public static void Main(string[] args)
BuildWebHost(args).Run();
}
- public static IWebHost BuildWebHost(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup()
- .Build();
+ public static IHost BuildWebHost(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup())
+ .Build();
public IConfigurationRoot Configuration { get; }
public IWebHostEnvironment CurrentEnvironment { get; }
diff --git a/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs b/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
deleted file mode 100644
index f69f65d..0000000
--- a/src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-using System;
-using System.Linq;
-using Microsoft.AspNetCore.Mvc.Filters;
-using Microsoft.Extensions.DependencyInjection;
-using Smidge.Models;
-
-namespace Smidge.Controllers
-{
- ///
- /// Adds the compression headers
- ///
- public sealed class AddCompressionHeaderAttribute : Attribute, IFilterFactory, IOrderedFilter
- {
- /// Creates an instance of the executable filter.
- /// The request .
- /// An instance of the executable filter.
- public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
- {
- return new AddCompressionFilter(
- serviceProvider.GetRequiredService(),
- serviceProvider.GetRequiredService());
- }
-
- public bool IsReusable => true;
-
- public int Order { get; set; }
-
- private class AddCompressionFilter : IActionFilter
- {
- private readonly IRequestHelper _requestHelper;
- private readonly IBundleManager _bundleManager;
-
- public AddCompressionFilter(IRequestHelper requestHelper, IBundleManager bundleManager)
- {
- _requestHelper = requestHelper ?? throw new ArgumentNullException(nameof(requestHelper));
- _bundleManager = bundleManager ?? throw new ArgumentNullException(nameof(bundleManager));
- }
-
- public void OnActionExecuting(ActionExecutingContext context)
- {
- if (context.ActionArguments.Count == 0)
- return;
-
- //put the model in the context, we'll resolve that after it's executed
- if (context.ActionArguments.First().Value is RequestModel file)
- context.HttpContext.Items[nameof(AddCompressionHeaderAttribute)] = file;
- }
-
- ///
- /// Adds the compression headers
- ///
- ///
- public void OnActionExecuted(ActionExecutedContext context)
- {
- if (context.Exception != null) return;
-
- //get the model from the items
- if (context.HttpContext.Items.TryGetValue(nameof(AddCompressionHeaderAttribute), out var requestModel) && requestModel is RequestModel file && file.IsBundleFound)
- {
- var enableCompression = true;
-
- //check if it's a bundle (not composite file)
- if (file is BundleRequestModel bundleRequest && _bundleManager.TryGetValue(bundleRequest.FileKey, out var bundle))
- {
- var bundleOptions = bundle.GetBundleOptions(_bundleManager, bundleRequest.Debug);
- enableCompression = bundleOptions.CompressResult;
- }
-
- if (enableCompression)
- context.HttpContext.Response.AddCompressionResponseHeader(_requestHelper.GetClientCompression(context.HttpContext.Request.Headers));
- }
- }
- }
- }
-}
diff --git a/src/Smidge/Controllers/AddCompressionHeaderEndpointFilter.cs b/src/Smidge/Controllers/AddCompressionHeaderEndpointFilter.cs
new file mode 100644
index 0000000..5fc8325
--- /dev/null
+++ b/src/Smidge/Controllers/AddCompressionHeaderEndpointFilter.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
+using Smidge.Models;
+
+namespace Smidge.Controllers
+{
+ ///
+ /// Adds the compression headers
+ ///
+ internal sealed class AddCompressionHeaderEndpointFilter : IEndpointFilter
+ {
+ private readonly IRequestHelper _requestHelper;
+ private readonly IBundleManager _bundleManager;
+
+ public AddCompressionHeaderEndpointFilter(IRequestHelper requestHelper, IBundleManager bundleManager)
+ {
+ _requestHelper = requestHelper ?? throw new ArgumentNullException(nameof(requestHelper));
+ _bundleManager = bundleManager ?? throw new ArgumentNullException(nameof(bundleManager));
+ }
+
+ public async ValueTask