1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-11-23 16:52:06 +01:00

Detect mimetypes

This commit is contained in:
adnano 2020-10-11 20:13:53 -04:00
parent 1c65b94f52
commit 38e6f42295

14
fs.go

@ -3,10 +3,18 @@ package gmi
import (
"errors"
"io"
"mime"
"os"
"path"
"path/filepath"
)
func init() {
// Add Gemini mime types
mime.AddExtensionType(".gmi", "text/gemini")
mime.AddExtensionType(".gemini", "text/gemini")
}
// FileServer errors.
var (
ErrNotAFile = errors.New("gemini: not a file")
@ -29,8 +37,10 @@ func (fsh fsHandler) Serve(rw *ResponseWriter, req *Request) {
NotFound(rw, req)
return
}
// TODO: detect mimetype
rw.SetMimetype("text/gemini")
// Detect mimetype
ext := filepath.Ext(path)
mimetype := mime.TypeByExtension(ext)
rw.SetMimetype(mimetype)
// Copy file to response writer
io.Copy(rw, f)
}