CWDev.StaticFileOptionsExtender
2.0.0
See the version list below for details.
dotnet add package CWDev.StaticFileOptionsExtender --version 2.0.0
NuGet\Install-Package CWDev.StaticFileOptionsExtender -Version 2.0.0
<PackageReference Include="CWDev.StaticFileOptionsExtender" Version="2.0.0" />
paket add CWDev.StaticFileOptionsExtender --version 2.0.0
#r "nuget: CWDev.StaticFileOptionsExtender, 2.0.0"
// Install CWDev.StaticFileOptionsExtender as a Cake Addin #addin nuget:?package=CWDev.StaticFileOptionsExtender&version=2.0.0 // Install CWDev.StaticFileOptionsExtender as a Cake Tool #tool nuget:?package=CWDev.StaticFileOptionsExtender&version=2.0.0
Static File Options Extender
Purpose:
- Enable .NET applications to serve static files which have been compressed via
gzip
and/orbrotli
compression algorithms, correctly mapping their original file's content-types and response headers. - Allow user to extend the Options Class to add additional compression types and configure mappings.
To Use:
using CWDev.StaticFileOptionsExtender;
var builder = WebApplication.CreateBuilder(args);
// ...
var app = builder.Build();
// ...
app.UseStaticFiles(StaticFileOptionsExtender.GetOptions()); // <--
Abstract:
.NET WebApplicationBuilder
can be leveraged to configure the application HTTP Request Pipeline.
Within that Pipeline StaticFileMiddleware
can be used to serve static files.
Typically, the app.UseStaticFiles(StaticFileOptions options)
middleware configures a few key
steps. This library is mostly concerned with TWO -- Providers and Handlers -- regarding:
- Mapping files
content-types
:IContentTypeProvider StaticFileOptions.ContentTypeProvider
*
- Adding or changing the response headers:
Action<StaticFileResponseContext> StaticFileOptions.OnPrepareResponse
*
StaticFileOptions StaticFileOptionsExtender.GetOptions
public static StaticFileOptions GetOptions()
{
var customFileTypeProvider = new CustomContentTypeProvider();
return new StaticFileOptions
{
ContentTypeProvider = customFileTypeProvider, // <-- *
OnPrepareResponse = (StaticFileResponseContext context) => // <-- *
{
// In addition to the MIME type also set the according encoding header (e.g. "br")
if (CompressionEncodings.TryGetValue(Path.GetExtension(context.File.Name), out string? encoding))
{
context.Context.Response.Headers.ContentEncoding = encoding;
}
}
};
}
Specifically, StaticFileOptionsExtender
leverages a class inheriting from IContentTypeProvider
to extend the MIME type mappings for the 380 most commonly used file types (default).
This library originally was built to enable .NET to serve static files which have been compressed for WebGL
by building from Unity.
Overview:
Contribute:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## Unreleased
### Added
- Contribute documentation to the README
## Version 2.0.0 - 06-28-25:
### Added
- Release notes to `nuspec`
- Git tags to release commits
### Changed
- Renamed namespace from `StaticFileOptionsExtender` to `CWDev` to remove redundancy in `using static` statement
## Version 1.0.2 - 06-28-24:
### Changed
- README documentation on...
- how to use...
## Version 1.0.0 - 06-28-24:
### Added
- `StaticFileOptionsExtender` namespace
- `StaticFileOptionsExtender` static class
- Namespace Icon
- License
- README documentation on...
- purpose...
- abstract...