in pkg/api/transport_custom.go [140:183]
func (t *CustomTransport) doRoundTrip(req *http.Request, retries int) (*http.Response, error) {
count := atomic.AddInt64(&t.count, 1)
if t.verbose {
handleVerboseRequest(t.writer, req, count, t.redactAuth)
}
res, err := t.rt.RoundTrip(req)
if t.verbose && res != nil {
handleVerboseResponse(t.writer, res, count)
}
if e, ok := err.(net.Error); ok && e.Timeout() {
if t.verbose {
msg := "request timed out, retrying..."
if retries <= 0 {
msg = "request timed out, giving up."
}
fmt.Fprintln(t.writer, msg)
}
if retries > 0 {
retries--
// Recursively do the roundtrip and return the result
<-time.After(backoff(t.backoff))
return t.doRoundTrip(req, retries)
}
}
if res != nil && !t.verbose {
_, _ = httputil.DumpResponse(res, res.Body != nil)
// When the content type is "text/html", a bit of tweaking is required
// for the response to be marshaled to JSON. Using the standard error
// definition and populating it with parts of the request so the error
// can be identified.
if strings.Contains(res.Header.Get(contentType), textHTMLContentType) {
res.Header.Set(contentType, jsonContentType)
res.Body = newProxyBody(req, res.StatusCode)
}
}
return res, err
}