MCPcopy
hub / github.com/grpc/grpc-go / sendRequest

Function sendRequest

credentials/sts/sts.go:297–321  ·  view source on GitHub ↗
(client httpDoer, req *http.Request)

Source from the content-addressed store, hash-verified

295}
296
297func sendRequest(client httpDoer, req *http.Request) ([]byte, error) {
298 // http.Client returns a non-nil error only if it encounters an error
299 // caused by client policy (such as CheckRedirect), or failure to speak
300 // HTTP (such as a network connectivity problem). A non-2xx status code
301 // doesn't cause an error.
302 resp, err := client.Do(req)
303 if err != nil {
304 return nil, err
305 }
306
307 // When the http.Client returns a non-nil error, it is the
308 // responsibility of the caller to read the response body till an EOF is
309 // encountered and to close it.
310 body, err := io.ReadAll(resp.Body)
311 resp.Body.Close()
312 if err != nil {
313 return nil, err
314 }
315
316 if resp.StatusCode == http.StatusOK {
317 return body, nil
318 }
319 logger.Warningf("http status %d, body: %s", resp.StatusCode, string(body))
320 return nil, fmt.Errorf("http status %d, body: %s", resp.StatusCode, string(body))
321}
322
323func tokenInfoFromResponse(respBody []byte) (*tokenInfo, error) {
324 respData := &responseParameters{}

Callers 2

GetRequestMetadataMethod · 0.85
TestSendRequestMethod · 0.85

Calls 4

DoMethod · 0.65
CloseMethod · 0.65
WarningfMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

TestSendRequestMethod · 0.68