MCPcopy Create free account
hub / github.com/cli/cli / DoRequest

Method DoRequest

api/client.go:262–280  ·  view source on GitHub ↗

DoRequest sends a request that the caller has already built, and returns the response for the caller to consume. It applies the same error handling as Request. Prefer Request. DoRequest exists for the few call sites that must control something Request cannot express. That is either a field of the r

(req *http.Request, opts ...RequestOption)

Source from the content-addressed store, hash-verified

260// Responses outside the 2xx range are returned as an HTTPError and their body is closed. On success
261// the response is returned unread and the caller is responsible for closing its body.
262func (c Client) DoRequest(req *http.Request, opts ...RequestOption) (*http.Response, error) {
263 cfg := newRequestConfig(opts)
264
265 resp, err := c.http.Do(req)
266 if err != nil {
267 return nil, err
268 }
269
270 success := resp.StatusCode >= 200 && resp.StatusCode < 300
271 if !success {
272 defer resp.Body.Close()
273 if cfg.endpointScopes != "" {
274 EndpointNeedsScopes(resp, cfg.endpointScopes)
275 }
276 return nil, HandleHTTPError(resp)
277 }
278
279 return resp, nil
280}
281
282// HandleHTTPError parses a http.Response into a HTTPError.
283//

Callers 6

uploadAssetFunction · 0.80
downloadAssetFunction · 0.80
postAssetMethod · 0.80
TestDoRequestFunction · 0.80
TestDoRequestErrorFunction · 0.80

Calls 5

newRequestConfigFunction · 0.85
EndpointNeedsScopesFunction · 0.85
HandleHTTPErrorFunction · 0.85
DoMethod · 0.65
CloseMethod · 0.65

Tested by 3

TestDoRequestFunction · 0.64
TestDoRequestErrorFunction · 0.64