Skip to content

Commit

Permalink
FIX: fix headers for multi strings
Browse files Browse the repository at this point in the history
- Return the native http.Headers object
  • Loading branch information
kynrai committed Jun 15, 2024
1 parent 4fc4787 commit 12ff228
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 2 additions & 9 deletions checks/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewHeaders(client *http.Client) *Headers {
return &Headers{client: client}
}

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

responseHeaders := make(map[string]string)
for k, v := range resp.Header {
for _, s := range v {
responseHeaders[k] = s
}
}

return responseHeaders, nil
return resp.Header, nil
}
6 changes: 3 additions & 3 deletions checks/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestList(t *testing.T) {

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

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

0 comments on commit 12ff228

Please sign in to comment.