From 0f2deb14d210d5db584f3d5bdb942ce1a5951ac9 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 5 Nov 2021 08:27:05 -0700 Subject: [PATCH] remove behavior of copyHeaders to copy all headers Previously, when no keys were specified, copyHeaders would copy all headers from src to dst. I believe this is a remnant of some old code, as we don't actually ever use that behavior today. I'm removing this as it seems too likely to accidentally pass along headers that shouldn't be. Instead, let's always be explicit about which headers to copy (which is what we currently do anyway). --- imageproxy.go | 16 +++++----------- imageproxy_test.go | 18 ------------------ 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/imageproxy.go b/imageproxy.go index 02c07e8..b304ea1 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -273,17 +273,11 @@ func peekContentType(p *bufio.Reader) string { return http.DetectContentType(byt) } -// copyHeader copies header values from src to dst, adding to any existing -// values with the same header name. If keys is not empty, only those header -// keys will be copied. -func copyHeader(dst, src http.Header, keys ...string) { - if len(keys) == 0 { - for k := range src { - keys = append(keys, k) - } - } - for _, key := range keys { - k := http.CanonicalHeaderKey(key) +// copyHeader copies values for specified headers from src to dst, adding to +// any existing values with the same header name. +func copyHeader(dst, src http.Header, headerNames ...string) { + for _, name := range headerNames { + k := http.CanonicalHeaderKey(name) for _, v := range src[k] { dst.Add(k, v) } diff --git a/imageproxy_test.go b/imageproxy_test.go index c2d4b82..87c2f5d 100644 --- a/imageproxy_test.go +++ b/imageproxy_test.go @@ -62,30 +62,12 @@ func TestCopyHeader(t *testing.T) { }, // copy headers - { - dst: http.Header{}, - src: http.Header{"A": []string{"a"}}, - keys: nil, - want: http.Header{"A": []string{"a"}}, - }, - { - dst: http.Header{"A": []string{"a"}}, - src: http.Header{"B": []string{"b"}}, - keys: nil, - want: http.Header{"A": []string{"a"}, "B": []string{"b"}}, - }, { dst: http.Header{"A": []string{"a"}}, src: http.Header{"B": []string{"b"}, "C": []string{"c"}}, keys: []string{"B"}, want: http.Header{"A": []string{"a"}, "B": []string{"b"}}, }, - { - dst: http.Header{"A": []string{"a1"}}, - src: http.Header{"A": []string{"a2"}}, - keys: nil, - want: http.Header{"A": []string{"a1", "a2"}}, - }, } for _, tt := range tests {