Support temporary and permanent redirects.
This commit is contained in:
parent
433c43e98e
commit
301d3409f1
|
@ -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)
|
||||
|
||||
|
|
10
handler.go
10
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 {
|
||||
|
|
Loading…
Reference in New Issue