(request *Request)
| 358 | } |
| 359 | |
| 360 | func (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 | |
| 385 | func (gateway Gateway) doRequestAndHandlerError(request *Request) (*http.Response, error) { |
| 386 | rawResponse, err := gateway.doRequest(request.HTTPReq) |
no test coverage detected