From 4a667a1026c7e95a143c6d5b8755776b8bbe1546 Mon Sep 17 00:00:00 2001 From: tuunit Date: Mon, 19 Dec 2022 16:38:05 +0100 Subject: [PATCH] fix: remove case sensitive checking of probe headers --- pkg/probe/http/request.go | 2 +- pkg/probe/http/request_test.go | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/pkg/probe/http/request.go b/pkg/probe/http/request.go index 4285c0a4ccb..fb7f818b249 100644 --- a/pkg/probe/http/request.go +++ b/pkg/probe/http/request.go @@ -113,7 +113,7 @@ func formatURL(scheme string, host string, port int, path string) *url.URL { func v1HeaderToHTTPHeader(headerList []v1.HTTPHeader) http.Header { headers := make(http.Header) for _, header := range headerList { - headers[header.Name] = append(headers[header.Name], header.Value) + headers.Add(header.Name, header.Value) } return headers } diff --git a/pkg/probe/http/request_test.go b/pkg/probe/http/request_test.go index 77c3d919596..bfd1a80e151 100644 --- a/pkg/probe/http/request_test.go +++ b/pkg/probe/http/request_test.go @@ -78,3 +78,49 @@ func Test_v1HeaderToHTTPHeader(t *testing.T) { }) } } + +func TestHeaderConversion(t *testing.T) { + testCases := []struct { + headers []v1.HTTPHeader + expected http.Header + }{ + { + []v1.HTTPHeader{ + { + Name: "Accept", + Value: "application/json", + }, + }, + http.Header{ + "Accept": []string{"application/json"}, + }, + }, + { + []v1.HTTPHeader{ + {Name: "accept", Value: "application/json"}, + }, + http.Header{ + "Accept": []string{"application/json"}, + }, + }, + { + []v1.HTTPHeader{ + {Name: "accept", Value: "application/json"}, + {Name: "Accept", Value: "*/*"}, + {Name: "pragma", Value: "no-cache"}, + {Name: "X-forwarded-for", Value: "username"}, + }, + http.Header{ + "Accept": []string{"application/json", "*/*"}, + "Pragma": []string{"no-cache"}, + "X-Forwarded-For": []string{"username"}, + }, + }, + } + for _, test := range testCases { + headers := v1HeaderToHTTPHeader(test.headers) + if !reflect.DeepEqual(headers, test.expected) { + t.Errorf("Expected %v, got %v", test.expected, headers) + } + } +}