MCPcopy
hub / github.com/perkeep/perkeep / serveFromDiskOrStatic

Method serveFromDiskOrStatic

pkg/server/ui.go:631–646  ·  view source on GitHub ↗

serveFromDiskOrStatic matches rx against req's path and serves the match either from disk (if non-nil) or from static (embedded in the binary).

(rw http.ResponseWriter, req *http.Request, rx *regexp.Regexp,
	disk http.Handler, static fs.FS)

Source from the content-addressed store, hash-verified

629
630// serveFromDiskOrStatic matches rx against req's path and serves the match either from disk (if non-nil) or from static (embedded in the binary).
631func (ui *UIHandler) serveFromDiskOrStatic(rw http.ResponseWriter, req *http.Request, rx *regexp.Regexp,
632 disk http.Handler, static fs.FS) {
633 suffix := httputil.PathSuffix(req)
634 m := rx.FindStringSubmatch(suffix)
635 if m == nil {
636 panic("Caller should verify that rx matches")
637 }
638 file := m[1]
639 if disk != nil {
640 req.URL.Path = "/" + file
641 disk.ServeHTTP(rw, req)
642 } else {
643 ServeStaticFile(rw, req, static, file)
644 }
645
646}
647
648func (ui *UIHandler) serveQR(rw http.ResponseWriter, req *http.Request) {
649 url := req.URL.Query().Get("url")

Callers 1

ServeHTTPMethod · 0.95

Calls 3

PathSuffixFunction · 0.92
ServeStaticFileFunction · 0.85
ServeHTTPMethod · 0.45

Tested by

no test coverage detected