calculateEtag computes an entity tag using a strong validator without consuming the contents of the file. It requires the file info contain the correct size and modification time. It strives to implement the semantics regarding ETags as defined by RFC 9110 section 8.8.3 and 8.8.1. See https://www.rf
(d os.FileInfo)
| 761 | // of Caddy deployments, stores mod times with millisecond precision, |
| 762 | // which we consider precise enough to qualify as a strong validator. |
| 763 | func calculateEtag(d os.FileInfo) string { |
| 764 | mtime := d.ModTime() |
| 765 | if !usefulModTime(mtime) { |
| 766 | return "" |
| 767 | } |
| 768 | var sb strings.Builder |
| 769 | sb.WriteRune('"') |
| 770 | sb.WriteString(strconv.FormatInt(mtime.UnixNano(), 36)) |
| 771 | sb.WriteString(strconv.FormatInt(d.Size(), 36)) |
| 772 | sb.WriteRune('"') |
| 773 | return sb.String() |
| 774 | } |
| 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) { |
no test coverage detected