| 515 | } |
| 516 | |
| 517 | func httpRequest(method string, url string, body any, basicAuthUsername, basicAuthPassword, xapikeyHeader, authorizationBearer, csrfTokenName, csrfTokenValue string, cookies []*http.Cookie, t *testing.T) *http.Response { |
| 518 | t.Helper() |
| 519 | |
| 520 | var bodyReader io.Reader = nil |
| 521 | if body != nil { |
| 522 | bodyBytes, err := json.Marshal(body) |
| 523 | if err != nil { |
| 524 | t.Fatal(err) |
| 525 | } |
| 526 | bodyReader = bytes.NewReader(bodyBytes) |
| 527 | } |
| 528 | |
| 529 | req, err := http.NewRequest(method, url, bodyReader) |
| 530 | if err != nil { |
| 531 | t.Fatal(err) |
| 532 | } |
| 533 | |
| 534 | if basicAuthUsername != "" || basicAuthPassword != "" { |
| 535 | req.SetBasicAuth(basicAuthUsername, basicAuthPassword) |
| 536 | } |
| 537 | |
| 538 | if xapikeyHeader != "" { |
| 539 | req.Header.Set("X-API-Key", xapikeyHeader) |
| 540 | } |
| 541 | |
| 542 | if authorizationBearer != "" { |
| 543 | req.Header.Set("Authorization", "Bearer "+authorizationBearer) |
| 544 | } |
| 545 | |
| 546 | if csrfTokenName != "" && csrfTokenValue != "" { |
| 547 | req.Header.Set("X-"+csrfTokenName, csrfTokenValue) |
| 548 | } |
| 549 | |
| 550 | for _, cookie := range cookies { |
| 551 | req.AddCookie(cookie) |
| 552 | } |
| 553 | |
| 554 | client := http.Client{Timeout: 15 * time.Second} |
| 555 | resp, err := client.Do(req) |
| 556 | if err != nil { |
| 557 | t.Fatal(err) |
| 558 | } |
| 559 | |
| 560 | return resp |
| 561 | } |
| 562 | |
| 563 | func httpGet(url string, basicAuthUsername, basicAuthPassword, xapikeyHeader, authorizationBearer string, cookies []*http.Cookie, t *testing.T) *http.Response { |
| 564 | t.Helper() |