diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index 509ced39685d09f8fbbc73b050aa063825f1f1f8..0000000000000000000000000000000000000000 --- a/CODEOWNERS +++ /dev/null @@ -1,6 +0,0 @@ -# Please see https://help.github.com/articles/about-codeowners/ for more information - -# Global owner -* @keks - -# Subsystem specific owners diff --git a/http/errors_test.go b/http/errors_test.go index f7f5e8d835efecbefcb1a95503c5915af62506f9..88c963dd9880167515754894970d2b9358511db0 100644 --- a/http/errors_test.go +++ b/http/errors_test.go @@ -92,7 +92,7 @@ func TestErrors(t *testing.T) { cmds.EncLong: "foobar", }, status: "400 Bad Request", - bodyStr: `invalid encoding: foobar`, + bodyStr: "invalid encoding: foobar\n", }, { diff --git a/http/handler.go b/http/handler.go index db01c448460dfc9538d55ab028442da3ac810fcb..35b069ef48cf07e1ab27af5b3284504a8dc604a8 100644 --- a/http/handler.go +++ b/http/handler.go @@ -96,8 +96,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { }() if !allowOrigin(r, h.cfg) || !allowReferer(r, h.cfg) { - w.WriteHeader(http.StatusForbidden) - w.Write([]byte("403 - Forbidden")) + http.Error(w, "403 - Forbidden", http.StatusForbidden) log.Warningf("API blocked request to %s. (possible CSRF)", r.URL) return } @@ -122,12 +121,12 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { req, err := parseRequest(r, h.root) if err != nil { + status := http.StatusBadRequest if err == ErrNotFound { - w.WriteHeader(http.StatusNotFound) - } else { - w.WriteHeader(http.StatusBadRequest) + status = http.StatusNotFound } - w.Write([]byte(err.Error())) + + http.Error(w, err.Error(), status) return } @@ -146,8 +145,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { re, err := NewResponseEmitter(w, r.Method, req, withRequestBodyEOFChan(bodyEOFChan)) if err != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return }