CWDev.StaticFileOptionsExtender 2.0.6

dotnet add package CWDev.StaticFileOptionsExtender --version 2.0.6                
NuGet\Install-Package CWDev.StaticFileOptionsExtender -Version 2.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CWDev.StaticFileOptionsExtender" Version="2.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CWDev.StaticFileOptionsExtender --version 2.0.6                
#r "nuget: CWDev.StaticFileOptionsExtender, 2.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CWDev.StaticFileOptionsExtender as a Cake Addin
#addin nuget:?package=CWDev.StaticFileOptionsExtender&version=2.0.6

// Install CWDev.StaticFileOptionsExtender as a Cake Tool
#tool nuget:?package=CWDev.StaticFileOptionsExtender&version=2.0.6                

Static File Options Extender

Purpose:

  1. Enable .NET applications to serve static files which have been compressed via gzip and/or brotli
    compression algorithms, correctly mapping their original file's content-types and response headers.
  2. Allow user to extend the Options Class to add additional compression types and configure mappings.

To Use:

  1. Leverage the package's static using directive*
  2. Call the package's GetOptions method as the argument to UseStaticFiles(...)*
    this will pass the extended StaticFileOptions while building the request pipeline.
using static CWDev.StaticFileOptionsExtender;      // <-- *

var builder = WebApplication.CreateBuilder(args);

// ...

var app = builder.Build();

// ...

app.UseStaticFiles(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) =>   // <-- *
        {
            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:

Release-Notes:

Contribute:

  • Please open a GitHub Issue with concerns.
  • Open a PR if you have a code proposal.
  • I will respond in <=24 hours with thoughts and/or solution.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.6 136 7/6/2024
2.0.5 112 7/6/2024
2.0.4 105 7/6/2024
2.0.3 99 6/30/2024
2.0.2 110 6/30/2024
2.0.1 97 6/29/2024
2.0.0 93 6/29/2024
1.0.1 100 6/28/2024
1.0.0 101 6/28/2024

=== Changelog
Also available at https://github.com/colinwilliams91/StaticFileOptionsExtender/blob/main/CHANGELOG.md
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
--- Unreleased
--- Added
- Cross-platform compatibility for .NET (Windows, macOS, Linux)
--- [Version 2.0.6](;;;) - 07-05-25
--- Changed
- `PreprocessChangelog.ps1` `CHANGELOG` formatting to correct remote rel path
 - after tests on `nuget Pack` exec in MSBuild yield bad results (this is another test)
--- [Version 2.0.5](./tree/v2.0.5) - 07-05-25:
--- Changed
- `PreprocessChangelog.ps1` formats `CHANGELOG` with links to remoge release-tag branches
 - testing on pack for MSBuild exec w/ XML element arg
--- [Version 2.0.4](./tree/v2.0.4) - 07-05-25:
--- Fixed
- `PreprocessChangelog.ps1` string replace methods order so formatting finds correct chars and replaces
--- [Version 2.0.3](./tree/v2.0.3) - 06-29-25:
--- Changed
- Move CWDev icon to `Assets\`
- Try to remove `Docs/` literal from documentation filenames
--- [Version 2.0.2](./tree/v2.0.5) - 06-29-25:
--- Added
- CHANGELOG_PLAIN.txt to format release notes readability for nuget.org
 - unpacked scripts for preprocessing and cleanup targetting Pack
--- Changed
- README readability
- DOCUMENTATION files to `\Docs` directory
--- [Version 2.0.1](./tree/v2.0.1) - 06-28-25:
--- Added
- README documentation on...
 - to contribute...
 - references to format and patterns for documentation (repo `CHANGELOG`)
--- Changed
- README documentation on...
 - how to use for updated Namespace (`CWDev`)
--- [Version 2.0.0](./tree/v2.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](./tree/v1.0.2) - 06-28-24:
--- Changed
- README documentation on...
- how to use...
--- [Version 1.0.0](./tree/v1.0.0) - 06-28-24:
--- Added
- `StaticFileOptionsExtender` namespace
- `StaticFileOptionsExtender` static class
- Namespace Icon
- License
- README documentation on...
- purpose...
- abstract...