forked from solderpunk/molly-brown
Add rudimentary support for specifying redirects.
This commit is contained in:
parent
548697b094
commit
11beddcfb1
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
DocBase string
|
DocBase string
|
||||||
HomeDocBase string
|
HomeDocBase string
|
||||||
LogPath string
|
LogPath string
|
||||||
|
Redirects map[string]string
|
||||||
CGIPath string
|
CGIPath string
|
||||||
SCGIPaths map[string]string
|
SCGIPaths map[string]string
|
||||||
}
|
}
|
||||||
|
@ -28,6 +29,7 @@ func getConfig(filename string) (Config, error) {
|
||||||
config.DocBase = "/var/gemini/"
|
config.DocBase = "/var/gemini/"
|
||||||
config.HomeDocBase = "users"
|
config.HomeDocBase = "users"
|
||||||
config.LogPath = "molly.log"
|
config.LogPath = "molly.log"
|
||||||
|
config.Redirects = make(map[string]string)
|
||||||
config.CGIPath = "^/var/gemini/cgi-bin/"
|
config.CGIPath = "^/var/gemini/cgi-bin/"
|
||||||
config.SCGIPaths = make(map[string]string)
|
config.SCGIPaths = make(map[string]string)
|
||||||
|
|
||||||
|
|
10
handler.go
10
handler.go
|
@ -72,6 +72,16 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
||||||
return
|
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
|
// Check whether this URL is mapped to an SCGI app
|
||||||
for scgi_url, scgi_socket := range config.SCGIPaths {
|
for scgi_url, scgi_socket := range config.SCGIPaths {
|
||||||
matched, err := regexp.Match(scgi_url, []byte(URL.Path))
|
matched, err := regexp.Match(scgi_url, []byte(URL.Path))
|
||||||
|
|
Loading…
Reference in New Issue