MCPcopy Create free account
hub / github.com/coder/coder / DupClientCopyingHeaders

Function DupClientCopyingHeaders

scaletest/loadtestutil/client.go:15–29  ·  view source on GitHub ↗

DupClientCopyingHeaders duplicates the Client, but with an independent underlying HTTP transport, so that it will not share connections with the client being duplicated. It copies any headers already on the existing transport as [codersdk.HeaderTransport] and add the headers in the argument.

(client *codersdk.Client, header http.Header)

Source from the content-addressed store, hash-verified

13// share connections with the client being duplicated. It copies any headers already on the existing transport as
14// [codersdk.HeaderTransport] and add the headers in the argument.
15func DupClientCopyingHeaders(client *codersdk.Client, header http.Header) (*codersdk.Client, error) {
16 nc := codersdk.New(client.URL, codersdk.WithLogger(client.Logger()))
17 nc.SessionTokenProvider = client.SessionTokenProvider
18 newHeader, t, err := extractHeaderAndInnerTransport(client.HTTPClient.Transport)
19 if err != nil {
20 return nil, xerrors.Errorf("extract headers: %w", err)
21 }
22 maps.Copy(newHeader, header)
23
24 nc.HTTPClient.Transport = &codersdk.HeaderTransport{
25 Transport: t.Clone(),
26 Header: newHeader,
27 }
28 return nc, nil
29}
30
31func extractHeaderAndInnerTransport(rt http.RoundTripper) (http.Header, *http.Transport, error) {
32 if t, ok := rt.(*http.Transport); ok {

Callers 14

scaletestChatMethod · 0.92
scaletestTaskStatusMethod · 0.92
scaletestPrebuildsMethod · 0.92
scaletestDashboardMethod · 0.92
scaletestAutostartMethod · 0.92
RunReturningUserMethod · 0.92
RunMethod · 0.92

Calls 7

NewFunction · 0.92
WithLoggerFunction · 0.92
CopyMethod · 0.65
LoggerMethod · 0.45
ErrorfMethod · 0.45
CloneMethod · 0.45

Tested by 1