From bcbf8a52ffef0f3f3b9b73a990d71b2b291a7cd6 Mon Sep 17 00:00:00 2001 From: Will McCutchen <will@mccutch.org> Date: Sat, 31 Dec 2016 23:02:51 -0500 Subject: [PATCH] Missing some early returns --- httpbin/handlers.go | 5 +++++ httpbin/handlers_test.go | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/httpbin/handlers.go b/httpbin/handlers.go index 0a2c55a..f4cd31b 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -63,6 +63,7 @@ func (h *HTTPBin) RequestWithBody(w http.ResponseWriter, r *http.Request) { err := parseBody(w, r, resp, h.options.MaxMemory) if err != nil { http.Error(w, fmt.Sprintf("error parsing request body: %s", err), http.StatusBadRequest) + return } body, _ := json.Marshal(resp) @@ -144,6 +145,7 @@ func (h *HTTPBin) Status(w http.ResponseWriter, r *http.Request) { code, err := strconv.Atoi(parts[2]) if err != nil { http.Error(w, "Invalid status", http.StatusBadRequest) + return } type statusCase struct { @@ -260,6 +262,7 @@ func doRedirect(w http.ResponseWriter, r *http.Request, relative bool) { n, err := strconv.Atoi(parts[2]) if err != nil || n < 1 { http.Error(w, "Invalid redirect", http.StatusBadRequest) + return } w.Header().Set("Location", redirectLocation(r, relative, n-1)) @@ -401,6 +404,7 @@ func (h *HTTPBin) Stream(w http.ResponseWriter, r *http.Request) { n, err := strconv.Atoi(parts[2]) if err != nil { http.Error(w, "Invalid integer", http.StatusBadRequest) + return } if n > 100 { @@ -440,6 +444,7 @@ func (h *HTTPBin) Delay(w http.ResponseWriter, r *http.Request) { n, err := strconv.ParseFloat(parts[2], 64) if err != nil { http.Error(w, "Invalid duration", http.StatusBadRequest) + return } delay = time.Duration(n*1000) * time.Millisecond } diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index 7c8da21..6071562 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -542,7 +542,6 @@ func TestPost__BodyTooBig(t *testing.T) { handler.ServeHTTP(w, r) assertStatusCode(t, w, http.StatusBadRequest) - assertContentType(t, w, jsonContentType) } func TestPost__QueryParams(t *testing.T) { -- GitLab