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

Method RequestWithContext

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

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

Callers 12

RequestMethod · 0.95
deleteAssetFunction · 0.80
FetchRefSHAFunction · 0.80
fetchReleasePathFunction · 0.80
getTopicsFunction · 0.80
setTopicsFunction · 0.80
CreateSubscriptionMethod · 0.80
OpenStreamMethod · 0.80
EventsFeaturesMethod · 0.80
getLatestReleaseInfoFunction · 0.80
RevokeTokenFunction · 0.80

Calls 4

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

Tested by 1