From 3e80488f92099a139702fbc37830f3aceec1ba44 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Wed, 10 Jun 2020 21:22:15 +0200 Subject: [PATCH] Add DefaultLang config variable to set text/gemini lang parameter. Overridable via .molly file. --- config.go | 3 +++ handler.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/config.go b/config.go index b0498d4..72f503a 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,7 @@ type Config struct { DocBase string HomeDocBase string GeminiExt string + DefaultLang string LogPath string TempRedirects map[string]string PermRedirects map[string]string @@ -21,6 +22,7 @@ type Config struct { type MollyFile struct { GeminiExt string + DefaultLang string } func getConfig(filename string) (Config, error) { @@ -35,6 +37,7 @@ func getConfig(filename string) (Config, error) { config.DocBase = "/var/gemini/" config.HomeDocBase = "users" config.GeminiExt = "gmi" + config.DefaultLang = "" config.LogPath = "molly.log" config.TempRedirects = make(map[string]string) config.PermRedirects = make(map[string]string) diff --git a/handler.go b/handler.go index 325b80c..4b100b5 100644 --- a/handler.go +++ b/handler.go @@ -256,6 +256,9 @@ func parseMollyFiles(path string, info os.FileInfo, config *Config) { if mollyFile.GeminiExt != "" { config.GeminiExt = mollyFile.GeminiExt } + if mollyFile.DefaultLang != "" { + config.DefaultLang = mollyFile.DefaultLang + } } } @@ -328,6 +331,10 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) { } else { mimeType = mime.TypeByExtension(ext) } + // Add lang parameter + if mimeType == "text/gemini" && config.DefaultLang != "" { + mimeType += "; lang=" + config.DefaultLang + } // Set a generic MIME type if the extension wasn't recognised if mimeType == "" { mimeType = "application/octet-stream"