aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handler.go9
-rw-r--r--main.go4
2 files changed, 12 insertions, 1 deletions
diff --git a/handler.go b/handler.go
index 75a8d2b..e484b27 100644
--- a/handler.go
+++ b/handler.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
+ "mime"
"net/url"
"os"
"path/filepath"
@@ -11,6 +12,11 @@ import (
gemini "git.sr.ht/~yotam/go-gemini"
)
+func absPathMime(path string) string {
+ ext := filepath.Ext(path)
+ return mime.TypeByExtension(ext)
+}
+
// Handler is the main handler of the server
type Handler struct {
cfg Config
@@ -75,5 +81,6 @@ func (h Handler) Handle(r gemini.Request) gemini.Response {
return gemini.ErrorResponse(err)
}
- return gemini.Response{Status: gemini.StatusSuccess, Meta: "text/gemini", Body: file}
+ meta := absPathMime(itemPath)
+ return gemini.Response{Status: gemini.StatusSuccess, Meta: meta, Body: file}
}
diff --git a/main.go b/main.go
index 1b00d45..37d9725 100644
--- a/main.go
+++ b/main.go
@@ -2,11 +2,15 @@ package main
import (
"log"
+ "mime"
gemini "git.sr.ht/~yotam/go-gemini"
)
func main() {
+ // gmi is not recognised by Go mime package so we have to manually add it
+ mime.AddExtensionType(".gmi", "text/gemini")
+
flags, err := getFlags()
if err != nil {
log.Fatal(err)