MCPcopy
hub / github.com/caddyserver/caddy / Provision

Method Provision

modules/caddyhttp/fileserver/staticfiles.go:194–267  ·  view source on GitHub ↗

Provision sets up the static files responder.

(ctx caddy.Context)

Source from the content-addressed store, hash-verified

192
193// Provision sets up the static files responder.
194func (fsrv *FileServer) Provision(ctx caddy.Context) error {
195 fsrv.logger = ctx.Logger()
196
197 fsrv.fsmap = ctx.FileSystems()
198
199 if fsrv.FileSystem == "" {
200 fsrv.FileSystem = "{http.vars.fs}"
201 }
202
203 if fsrv.Root == "" {
204 fsrv.Root = "{http.vars.root}"
205 }
206
207 if fsrv.IndexNames == nil {
208 fsrv.IndexNames = defaultIndexNames
209 }
210
211 // for hide paths that are static (i.e. no placeholders), we can transform them into
212 // absolute paths before the server starts for very slight performance improvement
213 for i, h := range fsrv.Hide {
214 if !strings.Contains(h, "{") && strings.Contains(h, separator) {
215 if abs, err := caddy.FastAbs(h); err == nil {
216 fsrv.Hide[i] = abs
217 }
218 }
219 }
220
221 // support precompressed sidecar files
222 mods, err := ctx.LoadModule(fsrv, "PrecompressedRaw")
223 if err != nil {
224 return fmt.Errorf("loading encoder modules: %v", err)
225 }
226 for modName, modIface := range mods.(map[string]any) {
227 p, ok := modIface.(encode.Precompressed)
228 if !ok {
229 return fmt.Errorf("module %s is not precompressor", modName)
230 }
231 ae := p.AcceptEncoding()
232 if ae == "" {
233 return fmt.Errorf("precompressor does not specify an Accept-Encoding value")
234 }
235 suffix := p.Suffix()
236 if suffix == "" {
237 return fmt.Errorf("precompressor does not specify a Suffix value")
238 }
239 if _, ok := fsrv.precompressors[ae]; ok {
240 return fmt.Errorf("precompressor already added: %s", ae)
241 }
242 if fsrv.precompressors == nil {
243 fsrv.precompressors = make(map[string]encode.Precompressed)
244 }
245 fsrv.precompressors[ae] = p
246 }
247
248 if fsrv.Browse != nil {
249 // check sort options
250 for idx, sortOption := range fsrv.Browse.SortOptions {
251 switch idx {

Callers 1

check_validator_headersFunction · 0.95

Calls 5

FileSystemsMethod · 0.80
LoadModuleMethod · 0.80
AcceptEncodingMethod · 0.65
SuffixMethod · 0.65
LoggerMethod · 0.45

Tested by 1

check_validator_headersFunction · 0.76