Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
encode: Tweak compression settings (#4215)
* Tweak compression settings zstd: Limit window sizes to 128K to keep memory in control both server and client size. zstd: Write 0 length frames. This may be needed for compatibility. zstd: Create fewer encoders. Small memory improvement. gzip: Allow -2 (Huffman only) and -3 (stateless) compression modes. * Update modules/caddyhttp/encode/zstd/zstd.go Update docs. Co-authored-by: Francis Lavoie <lavofr@gmail.com> Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Klaus Post committed
Jun 18, 2021 at 10:49 UTC
69c914483d448cae05ebc4b658a331682532d3d3
2 files changed
+8
-6
modules/caddyhttp/encode/gzip/gzip.go
+4
-5
@@ -15,7 +15,6 @@
15
package caddygzip
16
17
import (
18
- "compress/flate"
18
"fmt"
19
"strconv"
20
@@ -68,11 +67,11 @@ func (g *Gzip) Provision(ctx caddy.Context) error {
67
68
// Validate validates g's configuration.
69
func (g Gzip) Validate() error {
71
- if g.Level < flate.NoCompression {
72
- return fmt.Errorf("quality too low; must be >= %d", flate.NoCompression)
70
+ if g.Level < gzip.StatelessCompression {
71
+ return fmt.Errorf("quality too low; must be >= %d", gzip.StatelessCompression)
72
}
74
- if g.Level > flate.BestCompression {
75
- return fmt.Errorf("quality too high; must be <= %d", flate.BestCompression)
73
+ if g.Level > gzip.BestCompression {
74
+ return fmt.Errorf("quality too high; must be <= %d", gzip.BestCompression)
75
}
76
return nil
77
}
modules/caddyhttp/encode/zstd/zstd.go
+4
-1
@@ -47,7 +47,10 @@ func (Zstd) AcceptEncoding() string { return "zstd" }
47
48
// NewEncoder returns a new gzip writer.
49
func (z Zstd) NewEncoder() encode.Encoder {
50
- writer, _ := zstd.NewWriter(nil)
50
+ // The default of 8MB for the window is
51
+ // too large for many clients, so we limit
52
+ // it to 128K to lighten their load.
53
+ writer, _ := zstd.NewWriter(nil, zstd.WithWindowSize(128<<10), zstd.WithEncoderConcurrency(1), zstd.WithZeroFrames(true))
54
return writer
55
}
56