Add github.com/klauspost/compress/gzhttp wrapper around the request
handler. With MinSize(1024), responses ≥ 1 KB get gzip-encoded when
the client advertises Accept-Encoding: gzip; smaller bodies + 304
Not Modified pass through unchanged.
The wrapper auto-appends Vary: Accept-Encoding (compatible with the
existing Vary: Accept on directory.go's content-negotiated path).
Live-tested against zddc-server -root /tmp/empty:
GET / w/ Accept-Encoding: gzip → 20.9 KB compressed (was 80.9 KB
uncompressed). 74% reduction.
Decompresses cleanly back to the original bytes.
Helps every code path that bypasses Caddy: devshell pods, local dev
binaries, tests, anywhere zddc-server is hit directly. Production
behind Caddy already had compression at the proxy layer; this just
makes the Go server self-sufficient.
Tests in cmd/zddc-server/main_test.go cover:
- large body + Accept-Encoding → compressed + Vary header
- small body → not compressed (under MinSize)
- no Accept-Encoding header → plain bytes
11 lines
207 B
Modula-2
11 lines
207 B
Modula-2
module codeberg.org/VARASYS/ZDDC/zddc
|
|
|
|
go 1.24
|
|
|
|
require (
|
|
github.com/fsnotify/fsnotify v1.9.0
|
|
github.com/klauspost/compress v1.18.6
|
|
gopkg.in/yaml.v3 v3.0.1
|
|
)
|
|
|
|
require golang.org/x/sys v0.26.0 // indirect
|