]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Prohibit any other HTTP methods v2.0.0
authorSergey Matveev <stargrave@stargrave.org>
Thu, 5 Dec 2019 10:12:47 +0000 (13:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 5 Dec 2019 10:12:47 +0000 (13:12 +0300)
gocheese.go

index 3c6d1521a754d06edbce07a85fd72cb5f14f23b0..a11e03f04d0a398efd1c1d24f9437ea0142def0a 100644 (file)
@@ -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)
        }
 }