(url: string, init?: RequestInit, redirectCount = 0)
| 33 | const GITLAB_REQUEST_TIMEOUT_MS = 30_000; |
| 34 | |
| 35 | async function fetchGitLab(url: string, init?: RequestInit, redirectCount = 0): Promise<Response> { |
| 36 | const response = await fetchGitLabOnce(url, init); |
| 37 | if (!isGitLabRedirect(response.status)) { |
| 38 | return response; |
| 39 | } |
| 40 | |
| 41 | const location = response.headers.get('location'); |
| 42 | if (!location) { |
| 43 | return response; |
| 44 | } |
| 45 | |
| 46 | if (redirectCount >= MAX_GITLAB_REDIRECTS) { |
| 47 | throw new Error('GitLab request exceeded redirect limit'); |
| 48 | } |
| 49 | |
| 50 | const redirectUrl = new URL(location, url).toString(); |
| 51 | return fetchGitLab( |
| 52 | redirectUrl, |
| 53 | buildRedirectRequestInit(init, response.status, url, redirectUrl), |
| 54 | redirectCount + 1 |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | async function fetchGitLabOnce(url: string, init?: RequestInit): Promise<Response> { |
| 59 | const resolvedUrl = await resolveGitLabUrlSafely(url); |
no test coverage detected