Repository navigation
Description
Describe the bug
When a .br or .gz file exists in wwwroot without the corresponding uncompressed sibling, the static web assets pipeline generates an endpoint that assigns the decompressed content type but does not assign Content-Encoding. The response then misdescribes its own body: the headers claim the decompressed type while the bytes are still compressed. Toolchains such as Unity WebGL builds can produce only the compressed assets (see dotnet/aspnetcore#67884).
If the uncompressed sibling is present, the same physical file gets a correct endpoint carrying Content-Encoding: br. The two code paths disagree about how to describe identical bytes, and only the sibling-less case is wrong.
Beyond the response being self-inconsistent, the missing header has a concrete secondary effect under IIS. A non-empty text/* content type matches the text/* entry in the default IIS httpCompression/dynamicTypes list, which is enabled, so IIS applies dynamic compression to the already brotli encoded body and stamps Content-Encoding: gzip. The client then receives gzip wrapped around brotli.
Steps to reproduce
A minimal repro is attached. It is a plain Microsoft.NET.Sdk.Web project whose Program.cs is only app.MapStaticAssets(), with two folders that differ solely in whether the uncompressed sibling exists:
wwwroot/standalone/hello.js.br <- compressed representation only
wwwroot/paired/hello.js + hello.js.br <- both representations, for control
Both .br files are byte identical.
dotnet build- Inspect
obj/Debug/net10.0/staticwebassets.build.endpoints.json
standalone/hello.js.br Content-Type=text/javascript Content-Encoding=<MISSING>
paired/hello.js.br Content-Type=text/javascript Content-Encoding=br
- Drop an uncompressed
hello.jsintowwwroot/standalone/, rebuild, andstandalone/hello.js.brgainsContent-Encoding: br. Remove it and rebuild to go back.
Expected behavior
A standalone foo.js.br should be described consistently with the sibling case: recognised as a compressed representation, with Content-Encoding: br alongside the decompressed content type.
Failing that, it should not be given the decompressed content type at all. Emitting the decompressed content type without the encoding is the one combination that is clearly wrong, because it produces a response that misdescribes its own body.
Actual behavior
The decompressed Content-Type with no Content-Encoding. Clients that depend on the headers receive compressed bytes labeled as the decompressed type.
Other details
- Reproduced on SDK 10.0.400 and 9.0.317. Not applicable to 8.0.424, where
.brreceived no content type at all. - Relevant targets:
Microsoft.NET.Sdk.StaticWebAssets.Compression.targets, targetsResolveBuildCompressedStaticWebAssetsConfiguration(callsDiscoverPrecompressedAssets) andResolveBuildCompressedStaticWebAssets(callsApplyCompressionNegotiation).
Activity