MCPcopy
hub / github.com/cloudfoundry/cli / doRequestHandlingAuth

Method doRequestHandlingAuth

cf/net/gateway.go:360–383  ·  view source on GitHub ↗
(request *Request)

Source from the content-addressed store, hash-verified

358}
359
360func (gateway Gateway) doRequestHandlingAuth(request *Request) (*http.Response, error) {
361 httpReq := request.HTTPReq
362
363 if request.SeekableBody != nil {
364 httpReq.Body = ioutil.NopCloser(request.SeekableBody)
365 }
366
367 if gateway.authenticator != nil {
368 authHeader := request.HTTPReq.Header.Get("Authorization")
369 // in case the request is purposefully unauthenticated (invocation without prior login)
370 // do not attempt to refresh the token (it does not exist)
371 if authHeader != "" {
372 token, err := gateway.authenticator.RefreshToken(authHeader)
373 if err != nil {
374 return nil, err
375 }
376 // if the token has not been refreshed, token is equivalent to the previously set header value
377 httpReq.Header.Set("Authorization", token)
378 }
379 }
380
381 // perform request
382 return gateway.doRequestAndHandlerError(request)
383}
384
385func (gateway Gateway) doRequestAndHandlerError(request *Request) (*http.Response, error) {
386 rawResponse, err := gateway.doRequest(request.HTTPReq)

Callers 2

PerformRequestMethod · 0.95

Calls 4

GetMethod · 0.65
RefreshTokenMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected