Finds the first corresponding etag file for a given file in the file system and return its content
(fileSystem fs.FS, filename string)
| 775 | |
| 776 | // Finds the first corresponding etag file for a given file in the file system and return its content |
| 777 | func (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. |
no test coverage detected