MCPcopy
hub / github.com/dgraph-io/dgraph / fetchURL

Function fetchURL

dgraph/cmd/debuginfo/debugging.go:83–101  ·  view source on GitHub ↗

fetchURL fetches a profile from a URL using HTTP.

(source string, timeout time.Duration)

Source from the content-addressed store, hash-verified

81
82// fetchURL fetches a profile from a URL using HTTP.
83func 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
103func statusCodeError(resp *http.Response) error {
104 if resp.Header.Get("X-Go-Pprof") != "" &&

Callers 1

saveDebugFunction · 0.85

Calls 5

statusCodeErrorFunction · 0.85
WarningfMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected