From 47d0dc59381e4536a48b3ff92c0b6dd88864f6c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Aug 2021 11:37:51 +0200 Subject: [PATCH] chore(deps): bump golang from 1.16.6 to 1.17.0 in /.github/go (#185) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): bump golang from 1.16.6 to 1.17.0 in /.github/go Bumps golang from 1.16.6 to 1.17.0. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * fix: guard against writing HTTP Status 0 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Roberto Abdelkader Martínez Pérez --- .github/go/Dockerfile | 2 +- internal/server/data/resource.go | 4 +++- internal/server/httperror/error_test.go | 2 +- internal/server/model/handler.go | 2 ++ internal/server/user/mux/handlerbuilder.go | 4 +++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/go/Dockerfile b/.github/go/Dockerfile index bab1ca4..f8df45f 100644 --- a/.github/go/Dockerfile +++ b/.github/go/Dockerfile @@ -1 +1 @@ -FROM golang:1.16.6 +FROM golang:1.17.0 diff --git a/internal/server/data/resource.go b/internal/server/data/resource.go index 4e8026a..2cbe6f3 100644 --- a/internal/server/data/resource.go +++ b/internal/server/data/resource.go @@ -224,7 +224,9 @@ func setResponseCookies(w http.ResponseWriter, r *http.Request, h *model.Handler func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) { if !h.BodyOut { - h.Writer.WriteHeader(h.Status) + if h.Status != 0 { + h.Writer.WriteHeader(h.Status) + } h.BodyOut = true } diff --git a/internal/server/httperror/error_test.go b/internal/server/httperror/error_test.go index 7bc209d..71dc78b 100644 --- a/internal/server/httperror/error_test.go +++ b/internal/server/httperror/error_test.go @@ -29,7 +29,7 @@ import ( func TestErrorJSONSetsAppJsonContentType(t *testing.T) { w := httptest.NewRecorder() - httperror.ErrorJSON(w, "Not Important Here", 0) + httperror.ErrorJSON(w, "Not Important Here", 500) if v := w.Result().Header.Get("Content-Type"); v != "application/json; charset=utf-8" { t.Errorf("Content-Type header mismatch. Expected: %q, got: %q", "application/json; charset=utf-8", v) diff --git a/internal/server/model/handler.go b/internal/server/model/handler.go index ff9a76e..1faf951 100644 --- a/internal/server/model/handler.go +++ b/internal/server/model/handler.go @@ -51,3 +51,5 @@ type Handler struct { // The transfer of the body has started BodyOut bool } + +// TODO: add a Handler smart constructor to initialize Status to 200 diff --git a/internal/server/user/mux/handlerbuilder.go b/internal/server/user/mux/handlerbuilder.go index 6a6eece..97d1d23 100644 --- a/internal/server/user/mux/handlerbuilder.go +++ b/internal/server/user/mux/handlerbuilder.go @@ -77,7 +77,9 @@ func handlerBuilder(route model.Route) http.Handler { // In case of the user not setting /request/body if !h.BodyOut { - h.Writer.WriteHeader(h.Status) + if h.Status != 0 { + h.Writer.WriteHeader(h.Status) + } h.BodyOut = true }