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

Method RequestWithContext

api/client.go:221–242  ·  view source on GitHub ↗

RequestWithContext performs a REST request and returns the response for the caller to consume, rather than decoding it into a receiver as REST does. It exists for call sites that need access to the response itself: streaming bodies, non-JSON bodies, response headers, or the status code of a successf

(ctx context.Context, hostname string, method string, p string, body io.Reader, opts ...RequestOption)

Source from the content-addressed store, hash-verified

219// Responses outside the 2xx range are returned as an HTTPError and their body is closed. On success
220// the response is returned unread and the caller is responsible for closing its body.
221func (c Client) RequestWithContext(ctx context.Context, hostname string, method string, p string, body io.Reader, opts ...RequestOption) (*http.Response, error) {
222 cfg := newRequestConfig(opts)
223 clientOpts := clientOptions(hostname, c.http.Transport)
224 maps.Copy(clientOpts.Headers, cfg.headers)
225 if cfg.noFollowRedirects {
226 clientOpts.CheckRedirect = func(req *http.Request, via []*http.Request) error {
227 return http.ErrUseLastResponse
228 }
229 }
230
231 restClient, err := ghAPI.NewRESTClient(clientOpts)
232 if err != nil {
233 return nil, err
234 }
235
236 resp, err := restClient.RequestWithContext(ctx, method, p, body)
237 if err != nil {
238 return nil, handleRequestError(err, cfg.endpointScopes)
239 }
240
241 return resp, nil
242}
243
244// DoRequest sends a request that the caller has already built, and returns the response for the
245// caller to consume. It applies the same error handling as Request.

Callers 8

RequestMethod · 0.95
deleteAssetFunction · 0.80
FetchRefSHAFunction · 0.80
fetchReleasePathFunction · 0.80
getTopicsFunction · 0.80
setTopicsFunction · 0.80
getLatestReleaseInfoFunction · 0.80

Calls 4

newRequestConfigFunction · 0.85
clientOptionsFunction · 0.85
handleRequestErrorFunction · 0.85
CopyMethod · 0.45

Tested by 1