aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradnano <[email protected]>2020-10-11 20:13:53 -0400
committeradnano <[email protected]>2020-10-11 20:13:53 -0400
commit96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842 (patch)
treedcfcbb3328031c917079763ce52d60204be85446
parentUpdate comments (diff)
downloadgo-gemini-96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842.tar.xz
go-gemini-96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842.zip
Detect mimetypes
-rw-r--r--fs.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/fs.go b/fs.go
index 01e2618..f899782 100644
--- a/fs.go
+++ b/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)
}