M shared/storage/files/file.go →
shared/storage/files/file.go "hash/fnv"
"io"
"mime"
+ "net/http"
"os"
"path/filepath"
"strings"
file := &storage.File{
Path: path,
FSPath: filename,
- ContentType: mime.TypeByExtension(filepath.Ext(filename)),
+ ContentType: getContentType(filename, buf),
LastModified: stat.ModTime(),
Etag: etag,
Encodings: map[string]*buffer.Buffer{
".html",
)
}
+
+func getContentType(filename string, buf *buffer.Buffer) string {
+ ext := filepath.Ext(filename)
+ if ext == "" {
+ return http.DetectContentType(buf.FirstBlock())
+ }
+
+ return mime.TypeByExtension(ext)
+}