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

Function extractHeaderAndInnerTransport

scaletest/loadtestutil/client.go:31–51  ·  view source on GitHub ↗
(rt http.RoundTripper)

Source from the content-addressed store, hash-verified

29}
30
31func extractHeaderAndInnerTransport(rt http.RoundTripper) (http.Header, *http.Transport, error) {
32 if t, ok := rt.(*http.Transport); ok {
33 // base case
34 return make(http.Header), t, nil
35 }
36 if ht, ok := rt.(*codersdk.HeaderTransport); ok {
37 headers, t, err := extractHeaderAndInnerTransport(ht.Transport)
38 if err != nil {
39 return nil, nil, err
40 }
41 maps.Copy(headers, ht.Header)
42 return headers, t, nil
43 }
44 // unrecognized RoundTripper. Just return a default transport, since we only care about preserving headers.
45 t, ok := http.DefaultTransport.(*http.Transport)
46 if !ok {
47 // unhittable, unless the Go stdlib changes.
48 return nil, nil, xerrors.New("DefaultTransport is not *http.Transport")
49 }
50 return make(http.Header), t, nil
51}

Callers 1

DupClientCopyingHeadersFunction · 0.85

Calls 2

CopyMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected