MCPcopy
hub / github.com/angular/angular / doRequest

Method doRequest

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

Source from the content-addressed store, hash-verified

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

Callers 1

handleMethod · 0.95

Calls 14

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

Tested by

no test coverage detected