(rt http.RoundTripper)
| 29 | } |
| 30 | |
| 31 | func 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 | } |
no test coverage detected