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 --- USAGE | 4 ++-- main.go | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/USAGE b/USAGE index 3fea3fa..8196889 100644 --- a/USAGE +++ b/USAGE @@ -89,8 +89,8 @@ Running sets the abuse email address to EMAIL example: --abuse abuse@example.com - --upload-host HOST - all request to HOST host will serve files directly ($host/$file, while other hosts serve them on $host/u/$file) + --upload-host HOSTS + all request to hosts in the comma-separated list HOSTS will serve files directly ($host/$file, while other hosts serve them on $host/u/$file) example: --upload-host u.example.com --upload-url URL 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