From 60344f6707d5ea68a536f526aa290def66eb7d82 Mon Sep 17 00:00:00 2001 From: Yotam Nachum Date: Sat, 23 Nov 2019 22:23:11 +0200 Subject: Return the correct mime in response header --- handler.go | 9 ++++++++- main.go | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3