From: Sergey Matveev Date: Thu, 5 Dec 2019 10:12:47 +0000 (+0300) Subject: Prohibit any other HTTP methods X-Git-Tag: v2.0.0^0 X-Git-Url: http://www.git.cypherpunks.ru/?p=gocheese.git;a=commitdiff_plain;h=099686a6455463aa6ccba141da1481c82fdb0cec Prohibit any other HTTP methods --- diff --git a/gocheese.go b/gocheese.go index 3c6d152..a11e03f 100644 --- a/gocheese.go +++ b/gocheese.go @@ -359,7 +359,8 @@ func serveUpload(w http.ResponseWriter, r *http.Request) { } func handler(w http.ResponseWriter, r *http.Request) { - if r.Method == "GET" { + switch r.Method { + case "GET": var path string var autorefresh bool if strings.HasPrefix(r.URL.Path, *norefreshURLPath) { @@ -383,8 +384,10 @@ func handler(w http.ResponseWriter, r *http.Request) { } else { servePkg(w, r, parts[0], parts[1]) } - } else if r.Method == "POST" { + case "POST": serveUpload(w, r) + default: + http.Error(w, "unknown action", http.StatusBadRequest) } }