@@ -52,6 +52,9 @@ will be changed to the HTTPS port and the server will use HTTPS. If using
52
52
a public domain, ensure A/AAAA records are properly configured before
53
53
using this option.
54
54
55
+ By default, Zstandard and Gzip compression are enabled. Use --no-compress
56
+ to disable compression.
57
+
55
58
If --browse is enabled, requests for folders without an index file will
56
59
respond with a file listing.` ,
57
60
CobraFunc : func (cmd * cobra.Command ) {
@@ -62,6 +65,7 @@ respond with a file listing.`,
62
65
cmd .Flags ().BoolP ("templates" , "t" , false , "Enable template rendering" )
63
66
cmd .Flags ().BoolP ("access-log" , "a" , false , "Enable the access log" )
64
67
cmd .Flags ().BoolP ("debug" , "v" , false , "Enable verbose debug logs" )
68
+ cmd .Flags ().BoolP ("no-compress" , "" , false , "Disable Zstandard and Gzip compression" )
65
69
cmd .Flags ().StringSliceP ("precompressed" , "p" , []string {}, "Specify precompression file extensions. Compression preference implied from flag order." )
66
70
cmd .RunE = caddycmd .WrapCommandFuncForCobra (cmdFileServer )
67
71
cmd .AddCommand (& cobra.Command {
@@ -87,13 +91,34 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
87
91
templates := fs .Bool ("templates" )
88
92
accessLog := fs .Bool ("access-log" )
89
93
debug := fs .Bool ("debug" )
94
+ compress := ! fs .Bool ("no-compress" )
90
95
precompressed , err := fs .GetStringSlice ("precompressed" )
91
96
if err != nil {
92
97
return caddy .ExitCodeFailedStartup , fmt .Errorf ("invalid precompressed flag: %v" , err )
93
98
}
94
99
95
100
var handlers []json.RawMessage
96
101
102
+ if compress {
103
+ zstd , err := caddy .GetModule ("http.encoders.zstd" )
104
+ if err != nil {
105
+ return caddy .ExitCodeFailedStartup , err
106
+ }
107
+
108
+ gzip , err := caddy .GetModule ("http.encoders.gzip" )
109
+ if err != nil {
110
+ return caddy .ExitCodeFailedStartup , err
111
+ }
112
+
113
+ handlers = append (handlers , caddyconfig .JSONModuleObject (encode.Encode {
114
+ EncodingsRaw : caddy.ModuleMap {
115
+ "zstd" : caddyconfig .JSON (zstd .New (), nil ),
116
+ "gzip" : caddyconfig .JSON (gzip .New (), nil ),
117
+ },
118
+ Prefer : []string {"zstd" , "gzip" },
119
+ }, "handler" , "encode" , nil ))
120
+ }
121
+
97
122
if templates {
98
123
handler := caddytpl.Templates {FileRoot : root }
99
124
handlers = append (handlers , caddyconfig .JSONModuleObject (handler , "handler" , "templates" , nil ))
0 commit comments