MCPcopy Create free account
hub / github.com/angular/angular / doRequest

Method doRequest

packages/common/http/src/fetch.ts:156–370  ·  view source on GitHub ↗
(
    request: HttpRequest<any>,
    signal: AbortSignal,
    observer: Observer<HttpEvent<any>>,
  )

Source from the content-addressed store, hash-verified

154 }
155
156 private async doRequest(
157 request: HttpRequest<any>,
158 signal: AbortSignal,
159 observer: Observer<HttpEvent<any>>,
160 ): Promise<void> {
161 const init = this.createRequestInit(request);
162 let response;
163 try {
164 // Run fetch outside of Angular zone.
165 // This is due to Node.js fetch implementation (Undici) which uses a number of setTimeouts to check if
166 // the response should eventually timeout which causes extra CD cycles every 500ms
167 const fetchPromise = this.ngZone.runOutsideAngular(() =>
168 this.fetchImpl(request.urlWithParams, {signal, ...init}),
169 );
170
171 // Make sure Zone.js doesn't trigger false-positive unhandled promise
172 // error in case the Promise is rejected synchronously. See function
173 // description for additional information.
174 silenceSuperfluousUnhandledPromiseRejection(fetchPromise);
175
176 // Send the `Sent` event before awaiting the response.
177 observer.next({type: HttpEventType.Sent});
178
179 response = await fetchPromise;
180 } catch (error: any) {
181 observer.error(
182 new HttpErrorResponse({
183 error,
184 status: error.status ?? 0,
185 statusText: error.statusText,
186 url: request.urlWithParams,
187 headers: error.headers,
188 }),
189 );
190 return;
191 }
192
193 if (this.destroyRef.destroyed) {
194 await response.body?.cancel();
195 return;
196 }
197
198 const headers = new HttpHeaders(response.headers);
199 const statusText = response.statusText;
200 const url = response.url || request.urlWithParams;
201
202 let status = response.status;
203 let body: string | ArrayBuffer | Blob | object | null = null;
204
205 const reportDownloadProgress = request.reportProgress || request.reportDownloadProgress;
206 if (reportDownloadProgress) {
207 observer.next(new HttpHeaderResponse({headers, status, statusText, url}));
208 }
209
210 if (response.body) {
211 const contentType = response.headers.get(CONTENT_TYPE_HEADER) ?? '';
212
213 // Read Progress

Callers 1

handleMethod · 0.95

Calls 15

createRequestInitMethod · 0.95
concatChunksMethod · 0.95
parseBodyMethod · 0.95
throwBodyTooLargeErrorFunction · 0.85
getTextDecoderFunction · 0.85
errorMethod · 0.65
cancelMethod · 0.65
getMethod · 0.65
readMethod · 0.65
runMethod · 0.65
runOutsideAngularMethod · 0.45

Tested by

no test coverage detected