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

Method doRequest

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

Source from the content-addressed store, hash-verified

131 }
132
133 private async doRequest(
134 request: HttpRequest<any>,
135 signal: AbortSignal,
136 observer: Observer<HttpEvent<any>>,
137 ): Promise<void> {
138 const init = this.createRequestInit(request);
139 let response;
140 try {
141 // Run fetch outside of Angular zone.
142 // This is due to Node.js fetch implementation (Undici) which uses a number of setTimeouts to check if
143 // the response should eventually timeout which causes extra CD cycles every 500ms
144 const fetchPromise = this.ngZone.runOutsideAngular(() =>
145 this.fetchImpl(request.urlWithParams, {signal, ...init}),
146 );
147
148 // Make sure Zone.js doesn't trigger false-positive unhandled promise
149 // error in case the Promise is rejected synchronously. See function
150 // description for additional information.
151 silenceSuperfluousUnhandledPromiseRejection(fetchPromise);
152
153 // Send the `Sent` event before awaiting the response.
154 observer.next({type: HttpEventType.Sent});
155
156 response = await fetchPromise;
157 } catch (error: any) {
158 observer.error(
159 new HttpErrorResponse({
160 error,
161 status: error.status ?? 0,
162 statusText: error.statusText,
163 url: request.urlWithParams,
164 headers: error.headers,
165 }),
166 );
167 return;
168 }
169
170 const headers = new HttpHeaders(response.headers);
171 const statusText = response.statusText;
172 const url = response.url || request.urlWithParams;
173
174 let status = response.status;
175 let body: string | ArrayBuffer | Blob | object | null = null;
176
177 const reportDownloadProgress = request.reportProgress || request.reportDownloadProgress;
178 if (reportDownloadProgress) {
179 observer.next(new HttpHeaderResponse({headers, status, statusText, url}));
180 }
181
182 if (response.body) {
183 const contentType = response.headers.get(CONTENT_TYPE_HEADER) ?? '';
184
185 // Read Progress
186 const contentLength = response.headers.get('content-length');
187 const contentLengthValue = contentLength !== null ? Number(contentLength) : NaN;
188
189 if (
190 this.maxResponseSize !== null &&

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
getMethod · 0.65
cancelMethod · 0.65
readMethod · 0.65
runMethod · 0.65
runOutsideAngularMethod · 0.45

Tested by

no test coverage detected