(
request: HttpRequest<any>,
signal: AbortSignal,
observer: Observer<HttpEvent<any>>,
)
| 112 | } |
| 113 | |
| 114 | private async doRequest( |
| 115 | request: HttpRequest<any>, |
| 116 | signal: AbortSignal, |
| 117 | observer: Observer<HttpEvent<any>>, |
| 118 | ): Promise<void> { |
| 119 | const init = this.createRequestInit(request); |
| 120 | let response; |
| 121 | try { |
| 122 | // Run fetch outside of Angular zone. |
| 123 | // This is due to Node.js fetch implementation (Undici) which uses a number of setTimeouts to check if |
| 124 | // the response should eventually timeout which causes extra CD cycles every 500ms |
| 125 | const fetchPromise = this.ngZone.runOutsideAngular(() => |
| 126 | this.fetchImpl(request.urlWithParams, {signal, ...init}), |
| 127 | ); |
| 128 | |
| 129 | // Make sure Zone.js doesn't trigger false-positive unhandled promise |
| 130 | // error in case the Promise is rejected synchronously. See function |
| 131 | // description for additional information. |
| 132 | silenceSuperfluousUnhandledPromiseRejection(fetchPromise); |
| 133 | |
| 134 | // Send the `Sent` event before awaiting the response. |
| 135 | observer.next({type: HttpEventType.Sent}); |
| 136 | |
| 137 | response = await fetchPromise; |
| 138 | } catch (error: any) { |
| 139 | observer.error( |
| 140 | new HttpErrorResponse({ |
| 141 | error, |
| 142 | status: error.status ?? 0, |
| 143 | statusText: error.statusText, |
| 144 | url: request.urlWithParams, |
| 145 | headers: error.headers, |
| 146 | }), |
| 147 | ); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | const headers = new HttpHeaders(response.headers); |
| 152 | const statusText = response.statusText; |
| 153 | const url = response.url || request.urlWithParams; |
| 154 | |
| 155 | let status = response.status; |
| 156 | let body: string | ArrayBuffer | Blob | object | null = null; |
| 157 | |
| 158 | const reportDownloadProgress = request.reportProgress || request.reportDownloadProgress; |
| 159 | if (reportDownloadProgress) { |
| 160 | observer.next(new HttpHeaderResponse({headers, status, statusText, url})); |
| 161 | } |
| 162 | |
| 163 | if (response.body) { |
| 164 | // Read Progress |
| 165 | const contentLength = response.headers.get('content-length'); |
| 166 | const contentLengthValue = contentLength !== null ? Number(contentLength) : NaN; |
| 167 | |
| 168 | if ( |
| 169 | this.maxResponseSize !== null && |
| 170 | Number.isFinite(contentLengthValue) && |
| 171 | contentLengthValue > this.maxResponseSize |
no test coverage detected