Skip to content

Commit

Permalink
Fix layering
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Nov 1, 2024
1 parent 4520d91 commit bbf4ab6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions build/lib/layersChecker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build/lib/layersChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const CORE_TYPES = [
'RequestInit',
'Headers',
'Response',
'Body',
'__type',
'__global',
'PerformanceMark',
'PerformanceObserver',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import { bufferToStream, VSBuffer } from '../../../common/buffer.js';
import { CancellationToken } from '../../../common/cancellation.js';
import { canceled } from '../../../common/errors.js';
import { IHeaders, IRequestContext, IRequestOptions, OfflineError } from '../common/request.js';
import { IHeaders, IRequestContext, IRequestOptions, OfflineError } from './request.js';

export async function request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
export async function request(options: IRequestOptions, token: CancellationToken, isOnline?: () => boolean): Promise<IRequestContext> {
if (token.isCancellationRequested) {
throw canceled();
}
Expand All @@ -35,7 +35,7 @@ export async function request(options: IRequestOptions, token: CancellationToken
stream: bufferToStream(VSBuffer.wrap(new Uint8Array(await res.arrayBuffer()))),
};
} catch (err) {
if (!navigator.onLine) {
if (isOnline && !isOnline()) {
throw new OfflineError();
}
if (err?.name === 'AbortError') {
Expand All @@ -52,7 +52,7 @@ export async function request(options: IRequestOptions, token: CancellationToken

function getRequestHeaders(options: IRequestOptions) {
if (options.headers || options.user || options.password || options.proxyAuthorization) {
const headers: HeadersInit = new Headers();
const headers = new Headers();
outer: for (const k in options.headers) {
switch (k.toLowerCase()) {
case 'user-agent':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// eslint-disable-next-line local/code-import-patterns
import * as http from 'http';
// eslint-disable-next-line local/code-import-patterns
import { AddressInfo } from 'net';
import assert from 'assert';
import { CancellationToken, CancellationTokenSource } from '../../../../common/cancellation.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../test/common/utils.js';
import { request } from '../../browser/request.js';
import { request } from '../../common/requestImpl.js';
import { streamToBuffer } from '../../../../common/buffer.js';
import { flakySuite } from '../../../../test/common/testUtils.js';

flakySuite('Request', () => {

suite('Request', () => {

let port: number;
let server: http.Server;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/services/request/browser/requestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IRemoteAgentService, IRemoteAgentConnection } from '../../remote/common
import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';
import { CommandsRegistry } from '../../../../platform/commands/common/commands.js';
import { AbstractRequestService, AuthInfo, Credentials, IRequestService } from '../../../../platform/request/common/request.js';
import { request } from '../../../../base/parts/request/browser/request.js';
import { request } from '../../../../base/parts/request/common/requestImpl.js';
import { ILogService } from '../../../../platform/log/common/log.js';

export class BrowserRequestService extends AbstractRequestService implements IRequestService {
Expand All @@ -31,7 +31,7 @@ export class BrowserRequestService extends AbstractRequestService implements IRe
if (!options.proxyAuthorization) {
options.proxyAuthorization = this.configurationService.getValue<string>('http.proxyAuthorization');
}
const context = await this.logAndRequest(options, () => request(options, token));
const context = await this.logAndRequest(options, () => request(options, token, () => navigator.onLine));

const connection = this.remoteAgentService.getConnection();
if (connection && context.res.statusCode === 405) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AbstractRequestService, AuthInfo, Credentials, IRequestService } from '
import { INativeHostService } from '../../../../platform/native/common/native.js';
import { IRequestContext, IRequestOptions } from '../../../../base/parts/request/common/request.js';
import { CancellationToken } from '../../../../base/common/cancellation.js';
import { request } from '../../../../base/parts/request/browser/request.js';
import { request } from '../../../../base/parts/request/common/requestImpl.js';
import { ILogService } from '../../../../platform/log/common/log.js';

export class NativeRequestService extends AbstractRequestService implements IRequestService {
Expand All @@ -28,7 +28,7 @@ export class NativeRequestService extends AbstractRequestService implements IReq
if (!options.proxyAuthorization) {
options.proxyAuthorization = this.configurationService.getValue<string>('http.proxyAuthorization');
}
return this.logAndRequest(options, () => request(options, token));
return this.logAndRequest(options, () => request(options, token, () => navigator.onLine));
}

async resolveProxy(url: string): Promise<string | undefined> {
Expand Down

0 comments on commit bbf4ab6

Please sign in to comment.