Skip to content

Commit 9bc9d1f

Browse files
authored
FIX: fix headers for multi strings (#51)
- Return the native http.Headers object
1 parent 387d79f commit 9bc9d1f

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

checks/headers.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewHeaders(client *http.Client) *Headers {
1313
return &Headers{client: client}
1414
}
1515

16-
func (h *Headers) List(ctx context.Context, url string) (map[string]string, error) {
16+
func (h *Headers) List(ctx context.Context, url string) (http.Header, error) {
1717
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
1818
if err != nil {
1919
return nil, err
@@ -25,12 +25,5 @@ func (h *Headers) List(ctx context.Context, url string) (map[string]string, erro
2525
}
2626
defer resp.Body.Close()
2727

28-
responseHeaders := make(map[string]string)
29-
for k, v := range resp.Header {
30-
for _, s := range v {
31-
responseHeaders[k] = s
32-
}
33-
}
34-
35-
return responseHeaders, nil
28+
return resp.Header, nil
3629
}

checks/headers_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestList(t *testing.T) {
1414

1515
c := testutils.MockClient(&http.Response{
1616
Header: http.Header{
17-
"Cache-Control": {"private, max-age=0"},
17+
"Cache-Control": {"private", "max-age=0"},
1818
"X-Xss-Protection": {"0"},
1919
},
2020
})
@@ -23,6 +23,6 @@ func TestList(t *testing.T) {
2323
actual, err := h.List(context.Background(), "example.com")
2424
assert.NoError(t, err)
2525

26-
assert.Equal(t, "private, max-age=0", actual["Cache-Control"])
27-
assert.Equal(t, "0", actual["X-Xss-Protection"])
26+
assert.Equal(t, []string{"private", "max-age=0"}, actual["Cache-Control"])
27+
assert.Equal(t, []string{"0"}, actual["X-Xss-Protection"])
2828
}

0 commit comments

Comments
 (0)