fix gemini fileserver -- errors, mimetype
alex wennerberg alex@alexwennerberg.com
Mon, 26 Oct 2020 15:57:10 -0700
1 files changed,
9 insertions(+),
5 deletions(-)
jump to
M
gemini.go
→
gemini.go
@@ -2,6 +2,7 @@ package main
import ( "crypto/tls" + "mime" "strings" // "fmt" gmi "git.sr.ht/~adnano/go-gemini"@@ -43,16 +44,19 @@ }
filePath := path.Join(c.FilesDirectory, userName, fileName) log.Println("Request for gemini file at", filePath) data, err := ioutil.ReadFile(filePath) - // serve file? - // TODO write mimetype + if err != nil { - // TODO return 404 equivalent - log.Fatal(err) + w.WriteHeader(51, "Not Found") + return } + ext := filepath.Ext(filePath) + mimetype := mime.TypeByExtension(ext) + w.SetMimetype(mimetype) _, err = w.Write(data) if err != nil { - // return internal server error log.Fatal(err) + w.WriteHeader(40, "Internal server error") + return } }