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

Method getEtagFromFile

modules/caddyhttp/fileserver/staticfiles.go:777–794  ·  view source on GitHub ↗

Finds the first corresponding etag file for a given file in the file system and return its content

(fileSystem fs.FS, filename string)

Source from the content-addressed store, hash-verified

775
776// Finds the first corresponding etag file for a given file in the file system and return its content
777func (fsrv *FileServer) getEtagFromFile(fileSystem fs.FS, filename string) (string, error) {
778 for _, suffix := range fsrv.EtagFileExtensions {
779 etagFilename := filename + suffix
780 etag, err := fs.ReadFile(fileSystem, etagFilename)
781 if errors.Is(err, fs.ErrNotExist) {
782 continue
783 }
784 if err != nil {
785 return "", fmt.Errorf("cannot read etag from file %s: %v", etagFilename, err)
786 }
787
788 // Etags should not contain newline characters
789 etag = bytes.ReplaceAll(etag, []byte("\n"), []byte{})
790
791 return string(etag), nil
792 }
793 return "", nil
794}
795
796// redirect performs a redirect to a given path. The 'toPath' parameter
797// MUST be solely a path, and MUST NOT include a query.

Callers 1

ServeHTTPMethod · 0.95

Calls 2

ReadFileMethod · 0.80
ReplaceAllMethod · 0.80

Tested by

no test coverage detected