{"id":23699481,"url":"https://github.com/colinwilliams91/staticfileoptionsextender","last_synced_at":"2025-09-03T03:30:32.152Z","repository":{"id":246315597,"uuid":"820733078","full_name":"colinwilliams91/StaticFileOptionsExtender","owner":"colinwilliams91","description":"A .NET library that extends the content-type/MIME-type mappings for serving static files which have been compressed.","archived":false,"fork":false,"pushed_at":"2024-07-14T04:49:59.000Z","size":55,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T10:19:46.194Z","etag":null,"topics":["brotli","compression","csharp","dotnet","encoding-decoding","gzip","http-server","mappings","mime-types","pipeline","server","static-file-handler","unity","webgl"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/CWDev.StaticFileOptionsExtender/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/colinwilliams91.png","metadata":{"files":{"readme":"Docs/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-27T04:35:31.000Z","updated_at":"2024-11-27T05:50:48.000Z","dependencies_parsed_at":"2024-07-14T05:37:16.023Z","dependency_job_id":"8ef8cb33-6dc1-4246-b5e8-bece4947757b","html_url":"https://github.com/colinwilliams91/StaticFileOptionsExtender","commit_stats":null,"previous_names":["colinwilliams91/staticfileoptionsextender"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinwilliams91%2FStaticFileOptionsExtender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinwilliams91%2FStaticFileOptionsExtender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinwilliams91%2FStaticFileOptionsExtender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinwilliams91%2FStaticFileOptionsExtender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colinwilliams91","download_url":"https://codeload.github.com/colinwilliams91/StaticFileOptionsExtender/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231829157,"owners_count":18432747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brotli","compression","csharp","dotnet","encoding-decoding","gzip","http-server","mappings","mime-types","pipeline","server","static-file-handler","unity","webgl"],"created_at":"2024-12-30T08:11:29.503Z","updated_at":"2024-12-30T08:11:30.585Z","avatar_url":"https://github.com/colinwilliams91.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Static File Options Extender\n\n## Purpose:\n1. Enable .NET applications to serve static files which have been compressed via `gzip` and/or `brotli` \\\n    compression algorithms, correctly mapping their original file's content-types and response headers.\n2. Allow user to extend the Options Class to add additional compression types and configure mappings.\n\n## To Use:\n1. Leverage the package's `static using` directive*\n2. Call the package's `GetOptions` method as the argument to `UseStaticFiles(...)`* \\\n    this will pass the extended `StaticFileOptions` while building the request pipeline.\n```C#\nusing static CWDev.StaticFileOptionsExtender;      // \u003c-- *\n\nvar builder = WebApplication.CreateBuilder(args);\n\n// ...\n\nvar app = builder.Build();\n\n// ...\n\napp.UseStaticFiles(GetOptions());                  // \u003c-- *\n```\n\n## Abstract:\n.NET `WebApplicationBuilder` can be leveraged to configure the application HTTP Request Pipeline. \\\nWithin that Pipeline `StaticFileMiddleware` can be used to serve static files. \\\n\\\nTypically, the `app.UseStaticFiles(StaticFileOptions options)` middleware configures a few key \\\nsteps. This library is mostly concerned with TWO -- Providers and Handlers -- regarding:\n- Mapping files `content-types`:\n  - `IContentTypeProvider StaticFileOptions.ContentTypeProvider`*\n- Adding or changing the response headers:\n  - `Action\u003cStaticFileResponseContext\u003e StaticFileOptions.OnPrepareResponse`*\n\n`StaticFileOptions StaticFileOptionsExtender.GetOptions`\n```C#\npublic static StaticFileOptions GetOptions()\n{\n    var customFileTypeProvider = new CustomContentTypeProvider();\n    return new StaticFileOptions\n    {\n        ContentTypeProvider = customFileTypeProvider,                // \u003c-- *\n        OnPrepareResponse = (StaticFileResponseContext context) =\u003e   // \u003c-- *\n        {\n            if (CompressionEncodings.TryGetValue(Path.GetExtension(context.File.Name), out string? encoding))\n            {\n                context.Context.Response.Headers.ContentEncoding = encoding;\n            }\n        }\n    };\n}\n```\n\nSpecifically, `StaticFileOptionsExtender` leverages a class inheriting from `IContentTypeProvider` \\\nto extend the MIME type mappings for the 380 most commonly used file types (default). \\\nThis library originally was built to enable .NET to serve static files which have been compressed for WebGL \\\nby building from Unity.\n\n## Overview:\n\n## Release-Notes:\n- [CHANGELOG](https://github.com/colinwilliams91/StaticFileOptionsExtender/blob/main/CHANGELOG.md)\n  - 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)\n  - Commits follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) patterns\n\n## Contribute:\n- Please open a [GitHub Issue](https://github.com/colinwilliams91/StaticFileOptionsExtender/issues) with concerns.\n- Open a [PR](https://github.com/colinwilliams91/StaticFileOptionsExtender/pulls) if you have a code proposal.\n- I will respond in `\u003c=24` hours with thoughts and/or solution.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinwilliams91%2Fstaticfileoptionsextender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolinwilliams91%2Fstaticfileoptionsextender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinwilliams91%2Fstaticfileoptionsextender/lists"}