1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-09-29 16:31:18 +02:00

Detect mimetypes

This commit is contained in:
adnano 2020-10-11 20:13:53 -04:00
parent 92af3df4c5
commit 96390291bc

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)
}