From c24a4d6d637065d6fcccbd8d175d0005903a445a Mon Sep 17 00:00:00 2001 From: Havrileck Alexandre Date: Thu, 29 Apr 2021 22:01:57 +0200 Subject: [PATCH] fix(responsehandler): Avoid setting empty header --- pkg/s3-proxy/response-handler/utils.go | 7 +++++-- pkg/s3-proxy/response-handler/utils_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/s3-proxy/response-handler/utils.go b/pkg/s3-proxy/response-handler/utils.go index 760fc850..bcad7d87 100644 --- a/pkg/s3-proxy/response-handler/utils.go +++ b/pkg/s3-proxy/response-handler/utils.go @@ -42,8 +42,11 @@ func (h *handler) manageHeaders(helpersContent string, headersTpl map[string]str str := buf.String() // Remove all new lines str = reg.ReplaceAllString(str, "") - // Save data - res[k] = str + // Save data only if the header isn't empty + if str != "" { + // Save + res[k] = str + } } // Return diff --git a/pkg/s3-proxy/response-handler/utils_test.go b/pkg/s3-proxy/response-handler/utils_test.go index 7f9dcdd8..8e22af51 100644 --- a/pkg/s3-proxy/response-handler/utils_test.go +++ b/pkg/s3-proxy/response-handler/utils_test.go @@ -107,6 +107,19 @@ func Test_handler_manageHeaders(t *testing.T) { "h1": "fixed", }, }, + { + name: "empty header must be removed", + args: args{ + helpersContent: "", + headersTpl: map[string]string{ + "h1": "fixed", + "h2": "", + }, + }, + want: map[string]string{ + "h1": "fixed", + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {