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 }