MCPcopy Index your code
hub / github.com/coder/coder / TestPrepareClientHeaders

Function TestPrepareClientHeaders

aibridge/intercept/client_headers_test.go:13–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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)

Callers

nothing calls this directly

Calls 6

PrepareClientHeadersFunction · 0.92
RunMethod · 0.65
GetMethod · 0.65
EmptyMethod · 0.45
EqualMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected