MCPcopy
hub / github.com/cortesi/devd / notFound

Method notFound

fileserver/fileserver.go:351–411  ·  view source on GitHub ↗
(
	logger termlog.Logger,
	w http.ResponseWriter,
	r *http.Request,
	name string,
	dir *http.File,
)

Source from the content-addressed store, hash-verified

349}
350
351func (fserver *FileServer) notFound(
352 logger termlog.Logger,
353 w http.ResponseWriter,
354 r *http.Request,
355 name string,
356 dir *http.File,
357) (err error) {
358 sm := http.NewServeMux()
359 seen := make(map[string]bool)
360 for _, nfr := range fserver.NotFoundRoutes {
361 seen[nfr.MuxMatch()] = true
362 sm.HandleFunc(
363 nfr.MuxMatch(),
364 func(nfr routespec.RouteSpec) func(w http.ResponseWriter, r *http.Request) {
365 return func(w http.ResponseWriter, r *http.Request) {
366 if matchTypes(nfr.Value, r.URL.Path) {
367 for _, pth := range notFoundSearchPaths(name, nfr.Value) {
368 next, err := fserver.serveNotFoundFile(w, r, pth)
369 if err != nil {
370 logger.Shout("Unable to serve not-found override: %s", err)
371 }
372 if !next {
373 return
374 }
375 }
376 }
377 err = fserver.serve404(w)
378 if err != nil {
379 logger.Shout("Internal error: %s", err)
380 }
381 }
382 }(nfr),
383 )
384 }
385 if _, exists := seen["/"]; !exists {
386 sm.HandleFunc(
387 "/",
388 func(response http.ResponseWriter, request *http.Request) {
389 if dir != nil {
390 d, err := (*dir).Stat()
391 if err != nil {
392 logger.Shout("Internal error: %s", err)
393 return
394 }
395 if checkLastModified(response, request, d.ModTime()) {
396 return
397 }
398 fserver.dirList(logger, response, name, *dir)
399 return
400 }
401 err = fserver.serve404(w)
402 if err != nil {
403 logger.Shout("Internal error: %s", err)
404 }
405 },
406 )
407 }
408 handle, _ := sm.Handler(r)

Callers 1

serveFileMethod · 0.95

Calls 11

serveNotFoundFileMethod · 0.95
serve404Method · 0.95
dirListMethod · 0.95
matchTypesFunction · 0.85
notFoundSearchPathsFunction · 0.85
checkLastModifiedFunction · 0.85
StatMethod · 0.80
ModTimeMethod · 0.80
HandlerMethod · 0.65
MuxMatchMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected