From 301d3409f12e045fca64c864fb6b125134ed5c2e Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Mon, 8 Jun 2020 19:59:16 +0200 Subject: [PATCH] Support temporary and permanent redirects. --- config.go | 6 ++++-- handler.go | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 4735fc6..438f6d3 100644 --- a/config.go +++ b/config.go @@ -12,7 +12,8 @@ type Config struct { DocBase string HomeDocBase string LogPath string - Redirects map[string]string + TempRedirects map[string]string + PermRedirects map[string]string CGIPath string SCGIPaths map[string]string } @@ -29,7 +30,8 @@ func getConfig(filename string) (Config, error) { config.DocBase = "/var/gemini/" config.HomeDocBase = "users" config.LogPath = "molly.log" - config.Redirects = make(map[string]string) + config.TempRedirects = make(map[string]string) + config.PermRedirects = make(map[string]string) config.CGIPath = "^/var/gemini/cgi-bin/" config.SCGIPaths = make(map[string]string) diff --git a/handler.go b/handler.go index a5a34bc..b8f3479 100644 --- a/handler.go +++ b/handler.go @@ -73,7 +73,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) } // Check for redirects - for src, dst := range config.Redirects { + for src, dst := range config.TempRedirects { if URL.Path == src { URL.Path = dst conn.Write([]byte("30 " + URL.String() + "\r\n")) @@ -81,6 +81,14 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) return } } + for src, dst := range config.PermRedirects { + if URL.Path == src { + URL.Path = dst + conn.Write([]byte("31 " + URL.String() + "\r\n")) + log.Status = 31 + return + } + } // Check whether this URL is mapped to an SCGI app for scgi_url, scgi_socket := range config.SCGIPaths {