* Connects to a remote Git repository and sends a request. * * @param {Object} args * @param {HttpClient} args.http - The HTTP client to use for requests. * @param {ProgressCallback} [args.onProgress] - Callback for progress updates. * @param {string} [args.corsProxy] - Optional CORS
({
http,
onProgress,
corsProxy,
service,
url,
auth,
body,
headers,
})
| 183 | * @throws {HttpError} - If the HTTP request fails. |
| 184 | */ |
| 185 | static async connect({ |
| 186 | http, |
| 187 | onProgress, |
| 188 | corsProxy, |
| 189 | service, |
| 190 | url, |
| 191 | auth, |
| 192 | body, |
| 193 | headers, |
| 194 | }) { |
| 195 | // We already have the "correct" auth value at this point, but |
| 196 | // we need to strip out the username/password from the URL yet again. |
| 197 | const urlAuth = extractAuthFromUrl(url) |
| 198 | if (urlAuth) url = urlAuth.url |
| 199 | |
| 200 | if (corsProxy) url = corsProxify(corsProxy, url) |
| 201 | |
| 202 | headers['content-type'] = `application/x-${service}-request` |
| 203 | headers.accept = `application/x-${service}-result` |
| 204 | updateHeaders(headers, auth) |
| 205 | |
| 206 | const res = await http.request({ |
| 207 | onProgress, |
| 208 | method: 'POST', |
| 209 | url: `${url}/${service}`, |
| 210 | body, |
| 211 | headers, |
| 212 | }) |
| 213 | if (res.statusCode !== 200) { |
| 214 | const { response } = stringifyBody(res) |
| 215 | throw new HttpError(res.statusCode, res.statusMessage, response) |
| 216 | } |
| 217 | return res |
| 218 | } |
| 219 | } |
no test coverage detected