Files
269bdfd0f0 Add Brotli response compression behind a new webserver mode (#38637)
* Add Brotli response compression behind a new webserver mode

Add a "brotli" value to ServiceSettings.WebserverMode, selectable from the
System Console, that compresses API responses with Brotli for clients that
advertise it and falls back to gzip for those that do not. The default stays
"gzip", so Brotli is opt-in. brotli is a superset of gzip rather than an
alternative, so static files and file downloads keep gzip; two
ServiceSettings helpers replace the exact WebserverMode == "gzip" checks to
keep that true.

* Fix TestBulkImportKeepsLinesAfterNonFatalWorkerError password length for FIPS

FIPS mode enforces a 14-character minimum password length. The test's
collider-user fixture used a 9-character password, which only surfaces
as a failure when FIPS-mode CI actually runs (gated on go.mod changes).
Reuses the 16-character password already used elsewhere in this file.

* Fix TestImportUsernamRemap password length for FIPS

* Delete Accept-Ranges once brotli compression starts

Matches gzhttp's own default behavior: once a response is compressed,
a client must not be told ranges are supported on it, since a later
range request would have to be resolved against the compressed
stream. http.ServeContent sets Accept-Ranges unconditionally on any
seekable response, so this only mattered once compression actually
started.

* Keep file downloads on gzip instead of brotli

Large file downloads (logs, invoice PDFs, uploaded files) compress
about as well under gzip as under brotli, and brotli's memory
footprint scales with response size, so file-serving routes now use
APISessionRequiredGzip / APISessionRequiredTrustRequesterGzip, which
force brotli off regardless of WebserverMode.

* Keep the public file link on gzip instead of brotli

getPublicFile still used APIHandler, which is brotli-eligible, so a
brotli-capable client could still get a brotli-compressed response
from the public file link despite the earlier fix for the
session-authenticated file routes. Adds APIHandlerGzip alongside the
other two Gzip variants and switches the route to it.

* Gate Brotli compression behind a feature flag and split brotli.go out

Brotli is now negotiated automatically whenever ServiceSettings.WebserverMode
is "gzip" and the EnableBrotliCompression feature flag is on, instead of
requiring a separate "brotli" webserver mode in the System Console. The
Brotli-specific response writer and Accept-Encoding handling move into their
own brotli.go, leaving compression.go with just the shared gzip/Brotli
dispatch logic. go-brrr is bumped to v1.3.0.

* Remove remaining brotli WebserverMode references

WriteFileResponse still special-cased webserverMode == "brotli" for the
X-Uncompressed-Content-Length header, and the Cypress web server mode spec
still exercised selecting "brotli" from the dropdown. Neither is reachable
anymore since "brotli" is no longer a valid WebserverMode value.

* Regenerate Playwright default feature flags

EnableBrotliCompression was missing from the generated Playwright
default_feature_flags.ts, which make check-generated validates in CI.

* Add EnableBrotliCompression to the support packet golden fixture

TestSupportPacketMarshalGolden/config does a strict comparison against
this checked-in fixture, which didn't account for the new feature flag.

---------

Co-authored-by: Jesse Hallam <jesse@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2026-10-22 01:40:41 +08:00
..