requestService.ts ×13

Frontier kind: Code frontier

unlabeled · c_4b3820a92081

31 tests · 12014 LOC · 61 files · introduces 0 tests · 96 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges96 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1746 ranges12014 lines · 61 files · Browse complete extent
All tests (intent)
31 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.

2 files ranked by introduced lines: 96 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/request/node/requestService.ts 80 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- requestService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import type * as http from 'http';
7 > import type * as https from 'https';
8 > import { parse as parseUrl } from 'url';
9 > import { Promises, timeout } from '../../../base/common/async.js';
10 > import { streamToBufferReadableStream } from '../../../base/common/buffer.js';
11 > import { CancellationToken } from '../../../base/common/cancellation.js';
12 > import { CancellationError, getErrorMessage } from '../../../base/common/errors.js';
13 > import * as streams from '../../../base/common/stream.js';
14 > import { isBoolean, isNumber } from '../../../base/common/types.js';
15 > import { IRequestContext, IRequestOptions } from '../../../base/parts/request/common/request.js';
16 > import { IConfigurationService } from '../../configuration/common/configuration.js';
17 > import { INativeEnvironmentService } from '../../environment/common/environment.js';
18 > import { getResolvedShellEnv } from '../../shell/node/shellEnv.js';
19 > import { ILogService } from '../../log/common/log.js';
20 > import { AbstractRequestService, AuthInfo, Credentials, IRequestService, systemCertificatesNodeDefault } from '../common/request.js';
21 > import { Agent, getProxyAgent } from './proxy.js';
22 > import { createGunzip } from 'zlib';
23 >
24 > const TRANSIENT_ERROR_CODES = new Set([
25 > 'EAI_AGAIN', // DNS lookup timed out
26 > 'ECONNREFUSED', // Connection refused by server
27 > 'EHOSTDOWN', // Host is down
28 > 'EHOSTUNREACH', // No route to host
29 > 'ENETDOWN', // Network is down
30 > 'ENETUNREACH', // Network is unreachable
31 > 'EPROTO' // Protocol error (TLS/SSL handshake failure)
32 > ]);
33 >
34 > const IDEMPOTENT_HTTP_METHODS_REGEX = /^(GET|HEAD|OPTIONS)$/i;
35 >
36 function isTransientError(error: unknown): boolean {
37 if (error instanceof Error) {
41 return false;
42 }
44 > export interface IRawRequestFunction {
45 > (options: http.RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
46 > }
47 >
48 > export interface NodeRequestOptions extends IRequestOptions {
49 > agent?: Agent;
50 > strictSSL?: boolean;
51 > isChromiumNetwork?: boolean;
52 > getRawRequest?(options: IRequestOptions): IRawRequestFunction;
53 > }
54 >
55 > /**
56 > * This service exposes the `request` API, while using the global
57 > * or configured proxy settings.
58 > */
59 > export class RequestService extends AbstractRequestService implements IRequestService {
60 >
61 > declare readonly _serviceBrand: undefined;
62 >
63 > private proxyUrl?: string;
64 > private strictSSL: boolean | undefined;
65 > private authorization?: string;
66 > private shellEnvErrorLogged?: boolean;
67 >
68 > constructor(
69 private readonly machine: 'local' | 'remote',
70 @IConfigurationService private readonly configurationService: IConfigurationService,
80 }));
81 }
83 > private configure() {
84 this.proxyUrl = this.getConfigValue<string>('http.proxy');
85 this.strictSSL = !!this.getConfigValue<boolean>('http.proxyStrictSSL');
86 this.authorization = this.getConfigValue<string>('http.proxyAuthorization');
87 }
89 > async request(options: NodeRequestOptions, token: CancellationToken): Promise<IRequestContext> {
90 const { proxyUrl, strictSSL } = this;
91
118 return this.logAndRequest(options, () => nodeRequest(options, token));
119 }
121 > async resolveProxy(url: string): Promise<string | undefined> {
122 return undefined; // currently not implemented in node
123 }
125 > async lookupAuthorization(authInfo: AuthInfo): Promise<Credentials | undefined> {
126 return undefined; // currently not implemented in node
127 }
129 > async lookupKerberosAuthorization(urlStr: string): Promise<string | undefined> {
130 try {
131 const spnConfig = this.getConfigValue<string>('http.proxyKerberosServicePrincipal');
137 }
138 }
140 > async loadCertificates(): Promise<string[]> {
141 const proxyAgent = await import('@vscode/proxy-agent');
142 return proxyAgent.loadSystemCertificates({
145 });
146 }
148 > private getConfigValue<T>(key: string, fallback?: T): T | undefined {
149 if (this.machine === 'remote') {
150 return this.configurationService.getValue<T>(key);
153 return values.userLocalValue ?? values.defaultValue ?? fallback;
154 }
156 >
157 export async function lookupKerberosAuthorization(urlStr: string, spnConfig: string | undefined, logService: ILogService, logPrefix: string) {
158 const importKerberos = await import('kerberos');
165 return client.step('');
166 }
168 async function getNodeRequest(options: IRequestOptions): Promise<IRawRequestFunction> {
169 const endpoint = parseUrl(options.url!);
172 return module.request;
173 }
175 export async function nodeRequest(options: NodeRequestOptions, token: CancellationToken): Promise<IRequestContext> {
176 const maxRetries = 3;
197 throw lastError;
198 }
200 async function nodeRequestAttempt(options: NodeRequestOptions, token: CancellationToken): Promise<IRequestContext> {
201 return Promises.withAsyncBody<IRequestContext>(async (resolve, reject) => {
src/vs/platform/request/node/proxy.ts 16 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- proxy.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { parse as parseUrl, Url } from 'url';
7 > import { isBoolean } from '../../../base/common/types.js';
8 >
9 > export type Agent = any;
10 >
11 function getSystemProxyURI(requestURL: Url, env: typeof process.env): string | null {
12 if (requestURL.protocol === 'http:') {
18 return null;
19 }
20 > proxy.ts
21 > export interface IOptions {
22 > proxyUrl?: string;
23 > strictSSL?: boolean;
24 > }
25 >
26 export async function getProxyAgent(rawRequestURL: string, env: typeof process.env, options: IOptions = {}): Promise<Agent> {
27 const requestURL = parseUrl(rawRequestURL);