MCPcopy Index your code
hub / github.com/docker/docker-agent / doRequestWithCtx

Function doRequestWithCtx

pkg/httpclient/client_test.go:104–122  ·  view source on GitHub ↗

doRequestWithCtx is like doRequest but uses the supplied context for the outbound request, so callers can exercise context-derived header injection (e.g. session ID propagation).

(t *testing.T, ctx context.Context, opts ...Opt)

Source from the content-addressed store, hash-verified

102// the outbound request, so callers can exercise context-derived header
103// injection (e.g. session ID propagation).
104func doRequestWithCtx(t *testing.T, ctx context.Context, opts ...Opt) http.Header {
105 t.Helper()
106
107 var capturedHeaders http.Header
108 srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
109 capturedHeaders = r.Header
110 }))
111 defer srv.Close()
112
113 client := NewHTTPClient(ctx, opts...)
114 req, err := http.NewRequestWithContext(ctx, http.MethodGet, srv.URL, http.NoBody)
115 require.NoError(t, err)
116
117 resp, err := client.Do(req)
118 require.NoError(t, err)
119 defer func() { _ = resp.Body.Close() }()
120
121 return capturedHeaders
122}
123
124func TestSessionIDHeader_GatewayBoundOnly(t *testing.T) {
125 t.Parallel()

Callers 2

doRequestFunction · 0.85

Calls 3

DoMethod · 0.95
NewHTTPClientFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected