requestService.ts ×11

Frontier kind: Code frontier

unlabeled · c_5338c4d206fe

15 tests · 12074 LOC · 61 files · introduces 0 tests · 51 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges51 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1760 ranges12074 lines · 61 files · Browse complete extent
All tests (intent)
15 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 51 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/request/node/requestService.ts 51 introduced LOC · 11 ranges

Open complete file

173 }
174
175 > export async function nodeRequest(options: NodeRequestOptions, token: CancellationToken): Promise<IRequestContext> { requestService.ts
176 > const maxRetries = 3;
177 > let lastError: Error | undefined;
178 > const isIdempotent = IDEMPOTENT_HTTP_METHODS_REGEX.test(options.type || 'GET');
179 >
180 > for (let attempt = 1; attempt <= maxRetries; attempt++) {
181 > try {
182 > return await nodeRequestAttempt(options, token);
183 > } catch (error) {
184 lastError = error as Error;
185 if (error instanceof CancellationError) {
193 await timeout(100 * attempt, token);
194 }
196
197 throw lastError;
198 }
199
200 > async function nodeRequestAttempt(options: NodeRequestOptions, token: CancellationToken): Promise<IRequestContext> { requestService.ts
201 > return Promises.withAsyncBody<IRequestContext>(async (resolve, reject) => {
202 > const endpoint = parseUrl(options.url!);
203 > const rawRequest = options.getRawRequest
204 ? options.getRawRequest(options)
205 : await getNodeRequest(options);
207 const opts: https.RequestOptions & { cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached' } = {
208 hostname: endpoint.hostname,
209 > port: endpoint.port ? parseInt(endpoint.port) : (endpoint.protocol === 'https:' ? 443 : 80), requestService.ts
210 > protocol: endpoint.protocol,
211 > path: endpoint.path,
212 > method: options.type || 'GET',
213 > headers: options.headers,
214 > agent: options.agent,
215 > rejectUnauthorized: isBoolean(options.strictSSL) ? options.strictSSL : true
216 > };
217 >
218 > if (options.user && options.password) {
219 opts.auth = options.user + ':' + options.password;
220 }
222 > if (options.disableCache) {
223 opts.cache = 'no-store';
224 }
226 > const req = rawRequest(opts, (res: http.IncomingMessage) => {
227 const followRedirects: number = isNumber(options.followRedirects) ? options.followRedirects : 3;
228 if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
246 resolve({ res, stream: streamToBufferReadableStream(stream) } satisfies IRequestContext);
247 }
248 > }); requestService.ts
249 >
250 > req.on('error', reject);
251 >
252 > // Handle timeout
253 > if (options.timeout) {
254 // Chromium network requests do not support the `timeout` option
255 if (options.isChromiumNetwork) {
268 }
269 }
271 > // Chromium will abort the request if forbidden headers are set.
272 > // Ref https://source.chromium.org/chromium/chromium/src/+/main:services/network/public/cpp/header_util.cc;l=14-48;
273 > // for additional context.
274 > if (options.isChromiumNetwork) {
275 req.removeHeader('Content-Length');
276 }
278 > if (options.data) {
279 if (typeof options.data === 'string') {
280 req.write(options.data);
281 }
282 }
284 > req.end();
285 >
286 > const cancellationListener = token.onCancellationRequested(() => {
287 cancellationListener.dispose();
288 req.abort();
289
290 reject(new CancellationError());
291 > }); requestService.ts
292 >
293 > req.on('response', () => cancellationListener.dispose());
294 > req.on('error', () => cancellationListener.dispose());
295 > });
296 > }