From 9f3d137026822bc5891cf6575a321ccd9558d448 Mon Sep 17 00:00:00 2001 From: clsr Date: Sun, 24 Jul 2016 07:03:54 +0200 Subject: Make --upload-host be a list of hosts --- main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5f2d2f2..23743c4 100644 --- a/main.go +++ b/main.go @@ -39,11 +39,13 @@ func handle(w http.ResponseWriter, r *http.Request) { return } if r.Method == http.MethodGet || r.Method == http.MethodPost || r.Method == http.MethodHead { - if uploadHost != "" && r.Host == uploadHost { - handleFile(w, r) - } else { - http.DefaultServeMux.ServeHTTP(w, r) + for _, host := range strings.Split(uploadHost, ",") { + if r.Host == host { + handleFile(w, r) + return + } } + http.DefaultServeMux.ServeHTTP(w, r) } else { w.Header().Set("Allow", "POST, HEAD, OPTIONS, GET") if r.Method != http.MethodOptions { @@ -54,7 +56,7 @@ func handle(w http.ResponseWriter, r *http.Request) { func main() { flag.StringVar(&uploadUrl, "upload-url", "", "URL to serve uploads from") - flag.StringVar(&uploadHost, "upload-host", "", "host to serve uploads on") + flag.StringVar(&uploadHost, "upload-host", "", "comma-separated list of hosts to serve uploads on") flag.StringVar(&siteName, "name", "Gomf", "website name") flag.StringVar(&contactMail, "contact", "contact@example.com", "contact email address") flag.StringVar(&abuseMail, "abuse", "abuse@example.com", "abuse email address") @@ -98,10 +100,11 @@ func main() { if uploadUrl == "" { if uploadHost != "" { + host := strings.Split(uploadHost, ",")[0] if *listenHttps != "" { - uploadUrl = "https://" + uploadHost + "/" + uploadUrl = "https://" + host + "/" } else if *listenHttp != "" { - uploadUrl = "http://" + uploadHost + "/" + uploadUrl = "http://" + host + "/" } } else { if *listenHttps != "" { -- cgit