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

Method DoRequest

api/client.go:263–281  ·  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

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

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