Skip to content

Commit

Permalink
fix(responsehandler): Avoid setting empty header
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Jul 3, 2021
1 parent 4b83595 commit c24a4d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/s3-proxy/response-handler/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/s3-proxy/response-handler/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c24a4d6

Please # to comment.