| 519 | } |
| 520 | |
| 521 | func (pc *proxyContext) applyAuthHeaders(req *http.Request) { |
| 522 | if pc == nil || req == nil { |
| 523 | return |
| 524 | } |
| 525 | |
| 526 | if pc.httpClient != nil && pc.httpClient.Jar != nil && pc.instanceURL != nil { |
| 527 | cookies := pc.httpClient.Jar.Cookies(pc.instanceURL) |
| 528 | if len(cookies) > 0 { |
| 529 | var cookiePairs []string |
| 530 | for _, cookie := range cookies { |
| 531 | cookiePairs = append(cookiePairs, fmt.Sprintf("%s=%s", cookie.Name, cookie.Value)) |
| 532 | } |
| 533 | req.Header.Set("Cookie", strings.Join(cookiePairs, "; ")) |
| 534 | } else { |
| 535 | req.Header.Del("Cookie") |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | if pc.basicAuth != nil { |
| 540 | req.SetBasicAuth(pc.basicAuth.username, pc.basicAuth.password) |
| 541 | } else { |
| 542 | req.Header.Del("Authorization") |
| 543 | } |
| 544 | |
| 545 | if pc.apiKey != "" { |
| 546 | req.Header.Set("Authorization", "Bearer "+pc.apiKey) |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | func (pc *proxyContext) refreshSession(ctx context.Context) error { |
| 551 | if pc == nil || pc.session == nil { |