diff --git a/src/vs/platform/request/electron-main/requestMainService.ts b/src/vs/platform/request/electron-main/requestMainService.ts index 63ef58800a1a6..7589efa675f7c 100644 --- a/src/vs/platform/request/electron-main/requestMainService.ts +++ b/src/vs/platform/request/electron-main/requestMainService.ts @@ -15,6 +15,6 @@ function getRawRequest(options: IRequestOptions): IRawRequestFunction { export class RequestMainService extends NodeRequestService { override request(options: IRequestOptions, token: CancellationToken): Promise { - return super.request({ ...(options || {}), getRawRequest }, token); + return super.request({ ...(options || {}), getRawRequest, isChromiumNetwork: true }, token); } } diff --git a/src/vs/platform/request/node/requestService.ts b/src/vs/platform/request/node/requestService.ts index fd5683282552d..482636e68b719 100644 --- a/src/vs/platform/request/node/requestService.ts +++ b/src/vs/platform/request/node/requestService.ts @@ -29,6 +29,7 @@ export interface IRawRequestFunction { export interface NodeRequestOptions extends IRequestOptions { agent?: Agent; strictSSL?: boolean; + isChromiumNetwork?: boolean; getRawRequest?(options: IRequestOptions): IRawRequestFunction; } @@ -146,7 +147,12 @@ export class RequestService extends Disposable implements IRequestService { } else { let stream: streams.ReadableStreamEvents = res; - if (res.headers['content-encoding'] === 'gzip') { + // Responses from Electron net module should be treated as response + // from browser, which will apply gzip filter and decompress the response + // using zlib before passing the result to us. Following step can be bypassed + // in this case and proceed further. + // Refs https://source.chromium.org/chromium/chromium/src/+/main:net/url_request/url_request_http_job.cc;l=1266-1318 + if (!options.isChromiumNetwork && res.headers['content-encoding'] === 'gzip') { stream = res.pipe(createGunzip()); } @@ -160,6 +166,13 @@ export class RequestService extends Disposable implements IRequestService { req.setTimeout(options.timeout); } + // Chromium will abort the request if forbidden headers are set. + // Ref https://source.chromium.org/chromium/chromium/src/+/main:services/network/public/cpp/header_util.cc;l=14-48; + // for additional context. + if (options.isChromiumNetwork) { + req.removeHeader('Content-Length'); + } + if (options.data) { if (typeof options.data === 'string') { req.write(options.data);