diff options
| author | adnano <[email protected]> | 2020-10-11 20:13:53 -0400 |
|---|---|---|
| committer | adnano <[email protected]> | 2020-10-11 20:13:53 -0400 |
| commit | 96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842 (patch) | |
| tree | dcfcbb3328031c917079763ce52d60204be85446 | |
| parent | Update comments (diff) | |
| download | go-gemini-96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842.tar.xz go-gemini-96390291bcbcd3e5fdc6213bfcd6d9eb86fe5842.zip | |
Detect mimetypes
| -rw-r--r-- | fs.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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) } |