fetchURL fetches a profile from a URL using HTTP.
(source string, timeout time.Duration, tr http.RoundTripper)
| 523 | |
| 524 | // fetchURL fetches a profile from a URL using HTTP. |
| 525 | func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.ReadCloser, error) { |
| 526 | client := &http.Client{ |
| 527 | Transport: tr, |
| 528 | Timeout: timeout + 5*time.Second, |
| 529 | } |
| 530 | resp, err := client.Get(source) |
| 531 | if err != nil { |
| 532 | return nil, fmt.Errorf("http fetch: %v", err) |
| 533 | } |
| 534 | if resp.StatusCode != http.StatusOK { |
| 535 | defer resp.Body.Close() |
| 536 | return nil, statusCodeError(resp) |
| 537 | } |
| 538 | |
| 539 | return resp.Body, nil |
| 540 | } |
| 541 | |
| 542 | func statusCodeError(resp *http.Response) error { |
| 543 | if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") { |
no test coverage detected
searching dependent graphs…