all repos — flounder @ 89cd84ba7696efba6ec0427b8f312c873d5b6a2f

A small site builder for the Gemini protocol

fix gemini fileserver -- errors, mimetype
alex wennerberg alex@alexwennerberg.com
Mon, 26 Oct 2020 15:57:10 -0700
commit

89cd84ba7696efba6ec0427b8f312c873d5b6a2f

parent

375e32af23a03e8d06704af706a817cf5beb5129

1 files changed, 9 insertions(+), 5 deletions(-)

jump to
M gemini.gogemini.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 } }