fetchURL fetches a profile from a URL using HTTP.
(source string, timeout time.Duration)
| 81 | |
| 82 | // fetchURL fetches a profile from a URL using HTTP. |
| 83 | func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) { |
| 84 | client := &http.Client{ |
| 85 | Timeout: timeout, |
| 86 | } |
| 87 | resp, err := client.Get(source) |
| 88 | if err != nil { |
| 89 | return nil, fmt.Errorf("http fetch: %v", err) |
| 90 | } |
| 91 | if resp.StatusCode != http.StatusOK { |
| 92 | defer func() { |
| 93 | if err := resp.Body.Close(); err != nil { |
| 94 | glog.Warningf("error closing body: %v", err) |
| 95 | } |
| 96 | }() |
| 97 | return nil, statusCodeError(resp) |
| 98 | } |
| 99 | |
| 100 | return resp.Body, nil |
| 101 | } |
| 102 | |
| 103 | func statusCodeError(resp *http.Response) error { |
| 104 | if resp.Header.Get("X-Go-Pprof") != "" && |