mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add standard encodings to binary cache (#21921)
fixes: https://github.com/coder/internal/issues/1300 Adds brotli and zstd compression to the binary cache. Also refactors coderd's streaming encoding middleware to use the same standard set of compression algorithms, so we have them in one place.
This commit is contained in:
+7
-12
@@ -21,11 +21,9 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -1972,16 +1970,13 @@ func compressHandler(h http.Handler) http.Handler {
|
||||
"application/*",
|
||||
"image/*",
|
||||
)
|
||||
cmp.SetEncoder("br", func(w io.Writer, level int) io.Writer {
|
||||
return brotli.NewWriterLevel(w, level)
|
||||
})
|
||||
cmp.SetEncoder("zstd", func(w io.Writer, level int) io.Writer {
|
||||
zw, err := zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)))
|
||||
if err != nil {
|
||||
panic("invalid zstd compressor: " + err.Error())
|
||||
}
|
||||
return zw
|
||||
})
|
||||
for encoding := range site.StandardEncoders {
|
||||
writeCloserFn := site.StandardEncoders[encoding]
|
||||
cmp.SetEncoder(encoding, func(w io.Writer, level int) io.Writer {
|
||||
writeCloser := writeCloserFn(w, level)
|
||||
return writeCloser
|
||||
})
|
||||
}
|
||||
|
||||
return cmp.Handler(h)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user