MCPcopy Create free account
hub / github.com/cli/cli / TestRequestHeaderOverridesTransportDefault

Function TestRequestHeaderOverridesTransportDefault

api/request_test.go:87–100  ·  view source on GitHub ↗

The transport supplies default headers of its own, so a per-request header is only useful if it takes precedence over them.

(t *testing.T)

Source from the content-addressed store, hash-verified

85// The transport supplies default headers of its own, so a per-request header is only useful if it
86// takes precedence over them.
87func TestRequestHeaderOverridesTransportDefault(t *testing.T) {
88 reg := &httpmock.Registry{}
89 defer reg.Verify(t)
90 client := newTestClient(reg)
91
92 reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(200, "{}"))
93
94 resp, err := client.Request("github.com", http.MethodPost, "repos/OWNER/REPO/releases", nil,
95 WithHeader("Content-Type", "application/zip"))
96 require.NoError(t, err)
97 defer resp.Body.Close()
98
99 assert.Equal(t, "application/zip", reg.Requests[0].Header.Get("Content-Type"))
100}
101
102// Pre-auth call sites supply their own token because it is not yet in config, so an explicit
103// Authorization header must survive rather than be replaced by the transport.

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
StatusStringResponseFunction · 0.92
newTestClientFunction · 0.85
RequestMethod · 0.80
EqualMethod · 0.80
WithHeaderFunction · 0.70
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected