| 33 | } |
| 34 | |
| 35 | func TestCopyAll(t *testing.T) { |
| 36 | from := http.Header{ |
| 37 | "X-Test-1": {"value1", "value2"}, |
| 38 | "X-Test-2": {"value3"}, |
| 39 | "X-Test-3": nil, |
| 40 | } |
| 41 | |
| 42 | to := http.Header{ |
| 43 | "X-Test-1": {"oldvalue"}, |
| 44 | "X-Test-3": {"value4"}, |
| 45 | "X-Test-4": {"value5"}, |
| 46 | } |
| 47 | |
| 48 | testCases := []struct { |
| 49 | overwrite bool |
| 50 | expected http.Header |
| 51 | }{ |
| 52 | { |
| 53 | overwrite: false, |
| 54 | expected: http.Header{ |
| 55 | "X-Test-1": {"oldvalue"}, |
| 56 | "X-Test-2": {"value3"}, |
| 57 | "X-Test-3": {"value4"}, |
| 58 | "X-Test-4": {"value5"}, |
| 59 | }, |
| 60 | }, |
| 61 | { |
| 62 | overwrite: true, |
| 63 | expected: http.Header{ |
| 64 | "X-Test-1": {"value1", "value2"}, |
| 65 | "X-Test-2": {"value3"}, |
| 66 | "X-Test-3": {"value4"}, |
| 67 | "X-Test-4": {"value5"}, |
| 68 | }, |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | for _, tc := range testCases { |
| 73 | t.Run(fmt.Sprintf("overwrite=%v", tc.overwrite), func(t *testing.T) { |
| 74 | toCopy := to.Clone() // Clone to avoid modifying the original 'to' header |
| 75 | httpheaders.CopyAll(from, toCopy, tc.overwrite) |
| 76 | require.Equal(t, tc.expected, toCopy) |
| 77 | }) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestCopyFromRequest(t *testing.T) { |
| 82 | req, err := http.NewRequest(http.MethodGet, "http://example.com", nil) |