(url: string, options: RequestInit)
| 241 | } |
| 242 | |
| 243 | async function uploadRequestWithTimeout(url: string, options: RequestInit): Promise<XhrResponse> { |
| 244 | const requestUrl = toProxyUrl(url); |
| 245 | |
| 246 | return new Promise((resolve, reject) => { |
| 247 | const xhr = new XMLHttpRequest(); |
| 248 | activeXhr = xhr; |
| 249 | const stallMs = getUploadTimeoutMs(); |
| 250 | let timeout = setTimeout(() => xhr.abort(), stallMs); |
| 251 | const resetStallTimeout = () => { |
| 252 | clearTimeout(timeout); |
| 253 | timeout = setTimeout(() => xhr.abort(), stallMs); |
| 254 | }; |
| 255 | |
| 256 | xhr.open(options.method || "GET", requestUrl); |
| 257 | |
| 258 | for (const [key, value] of getHeaderEntries(options.headers)) { |
| 259 | xhr.setRequestHeader(key, value); |
| 260 | } |
| 261 | |
| 262 | xhr.upload.onprogress = event => { |
| 263 | resetStallTimeout(); |
| 264 | setXhrUploadProgress(event); |
| 265 | }; |
| 266 | xhr.onload = () => resolve(new XhrResponse(xhr)); |
| 267 | xhr.onerror = () => reject(new Error("Upload failed")); |
| 268 | xhr.onabort = () => reject(new Error(cancelRequested ? "Upload cancelled by user" : "Upload timed out")); |
| 269 | xhr.onloadend = () => { |
| 270 | clearTimeout(timeout); |
| 271 | xhr.upload.onprogress = null; |
| 272 | if (activeXhr === xhr) { |
| 273 | activeXhr = null; |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | const { body } = options; |
| 278 | xhr.send(body instanceof ReadableStream ? null : body as XMLHttpRequestBodyInit | null); |
| 279 | }); |
| 280 | } |
| 281 | |
| 282 | function resolveShareXRequestValue(value: string | number | boolean, filename: string): string { |
| 283 | return String(value) |
no test coverage detected