flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 89cd84ba7696efba6ec0427b8f312c873d5b6a2f
parent 375e32af23a03e8d06704af706a817cf5beb5129
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 26 Oct 2020 15:57:10 -0700

fix gemini fileserver -- errors, mimetype

Diffstat:
Mgemini.go | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gemini.go b/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 @@ func gmiPage(w *gmi.ResponseWriter, r *gmi.Request) { 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 } }