aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2016-07-24 07:03:54 +0200
committerclsr <clsr@clsr.net>2016-07-24 07:03:54 +0200
commit9f3d137026822bc5891cf6575a321ccd9558d448 (patch)
tree09d74adb4eb86a305dfc408347a4e3fa350f0f50
parent244da8ad70fbda7f9c97051d9c3d8901e143f9cc (diff)
downloadgomf-9f3d137026822bc5891cf6575a321ccd9558d448.tar.gz
gomf-9f3d137026822bc5891cf6575a321ccd9558d448.zip
Make --upload-host be a list of hostsv0.4.2
-rw-r--r--USAGE4
-rw-r--r--main.go17
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 != "" {