1
0
Fork 0

Add rudimentary support for specifying redirects.

This commit is contained in:
Solderpunk 2020-06-06 13:36:10 +02:00
parent 548697b094
commit 11beddcfb1
2 changed files with 12 additions and 0 deletions

View file

@ -12,6 +12,7 @@ type Config struct {
DocBase string
HomeDocBase string
LogPath string
Redirects map[string]string
CGIPath string
SCGIPaths map[string]string
}
@ -28,6 +29,7 @@ func getConfig(filename string) (Config, error) {
config.DocBase = "/var/gemini/"
config.HomeDocBase = "users"
config.LogPath = "molly.log"
config.Redirects = make(map[string]string)
config.CGIPath = "^/var/gemini/cgi-bin/"
config.SCGIPaths = make(map[string]string)

View file

@ -72,6 +72,16 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
return
}
// Check for redirects
for src, dst := range config.Redirects {
if URL.Path == src {
URL.Path = dst
conn.Write([]byte("30 " + URL.String() + "\r\n"))
log.Status = 30
return
}
}
// Check whether this URL is mapped to an SCGI app
for scgi_url, scgi_socket := range config.SCGIPaths {
matched, err := regexp.Match(scgi_url, []byte(URL.Path))