diff --git a/httpbin/handlers.go b/httpbin/handlers.go index 0a2c55ae6baeee6d34e164c3d214e6cb52bec8da..f4cd31bed7fec39558fe41aa403f9d8714fc5eb0 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 7c8da21d0cbe4d10387cbcce20a91f8f96ef2e0f..6071562c8f061e8410197f15830a46e9beed4b06 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) {