From 0232d86f8accd0b393126f85e85aa4bba57cce1b Mon Sep 17 00:00:00 2001 From: Stas Merzlyakov Date: Mon, 18 Mar 2024 13:47:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D0=BB=20Body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/adapter/http/handler/metric_operation_handler.go | 2 ++ .../http/middleware/compress/uncompress_gzip_request_mw_test.go | 1 + 2 files changed, 3 insertions(+) diff --git a/internal/server/adapter/http/handler/metric_operation_handler.go b/internal/server/adapter/http/handler/metric_operation_handler.go index dd08cf6..6d1f61b 100644 --- a/internal/server/adapter/http/handler/metric_operation_handler.go +++ b/internal/server/adapter/http/handler/metric_operation_handler.go @@ -175,6 +175,7 @@ func (h *metricOperationAdapter) PostGauge(w http.ResponseWriter, req *http.Requ opName := "PostGauge" _, _ = io.ReadAll(req.Body) + defer req.Body.Close() if !h.isContentTypeExpected(TextPlain, w, req) { return @@ -209,6 +210,7 @@ func (h *metricOperationAdapter) PostCounter(w http.ResponseWriter, req *http.Re opName := "PostCounter" _, _ = io.ReadAll(req.Body) + defer req.Body.Close() if !h.isContentTypeExpected(TextPlain, w, req) { return diff --git a/internal/server/adapter/http/middleware/compress/uncompress_gzip_request_mw_test.go b/internal/server/adapter/http/middleware/compress/uncompress_gzip_request_mw_test.go index d3d10ef..76f0c8d 100644 --- a/internal/server/adapter/http/middleware/compress/uncompress_gzip_request_mw_test.go +++ b/internal/server/adapter/http/middleware/compress/uncompress_gzip_request_mw_test.go @@ -36,6 +36,7 @@ func TestUncompressGZIPRequestMW(t *testing.T) { mockHandler.EXPECT().ServeHTTP(gomock.Any(), gomock.Any()).DoAndReturn( func(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) + defer r.Body.Close() if err != nil && err != io.EOF { http.Error(w, "read body err", http.StatusInternalServerError)