| 11 | ) |
| 12 | |
| 13 | func TestPrepareClientHeaders(t *testing.T) { |
| 14 | t.Parallel() |
| 15 | |
| 16 | t.Run("nil input returns empty header", func(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | result := intercept.PrepareClientHeaders(nil) |
| 20 | require.Empty(t, result) |
| 21 | }) |
| 22 | |
| 23 | t.Run("hop-by-hop headers are removed", func(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | |
| 26 | input := http.Header{ |
| 27 | "Connection": {"keep-alive"}, |
| 28 | "Keep-Alive": {"timeout=5"}, |
| 29 | "Transfer-Encoding": {"chunked"}, |
| 30 | "Upgrade": {"websocket"}, |
| 31 | "X-Custom": {"preserved"}, |
| 32 | } |
| 33 | |
| 34 | result := intercept.PrepareClientHeaders(input) |
| 35 | |
| 36 | assert.Empty(t, result.Get("Connection")) |
| 37 | assert.Empty(t, result.Get("Keep-Alive")) |
| 38 | assert.Empty(t, result.Get("Transfer-Encoding")) |
| 39 | assert.Empty(t, result.Get("Upgrade")) |
| 40 | assert.Equal(t, "preserved", result.Get("X-Custom")) |
| 41 | }) |
| 42 | |
| 43 | t.Run("non-forwarded headers are removed", func(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | |
| 46 | input := http.Header{ |
| 47 | "Host": {"example.com"}, |
| 48 | "Accept-Encoding": {"gzip"}, |
| 49 | "Content-Length": {"42"}, |
| 50 | "X-Custom": {"preserved"}, |
| 51 | } |
| 52 | |
| 53 | result := intercept.PrepareClientHeaders(input) |
| 54 | |
| 55 | assert.Empty(t, result.Get("Host")) |
| 56 | assert.Empty(t, result.Get("Accept-Encoding")) |
| 57 | assert.Empty(t, result.Get("Content-Length")) |
| 58 | assert.Equal(t, "preserved", result.Get("X-Custom")) |
| 59 | }) |
| 60 | |
| 61 | t.Run("auth headers are removed", func(t *testing.T) { |
| 62 | t.Parallel() |
| 63 | |
| 64 | input := http.Header{ |
| 65 | "Authorization": {"Bearer coder-session-token"}, |
| 66 | "X-Api-Key": {"sk-client-key"}, |
| 67 | "X-Custom": {"preserved"}, |
| 68 | } |
| 69 | |
| 70 | result := intercept.PrepareClientHeaders(input) |