Skip to content

Commit 0f8089f

Browse files
authored
fix: main request service for Electron.net requests (microsoft#167075)
1 parent 0306f1e commit 0f8089f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/vs/platform/request/electron-main/requestMainService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ function getRawRequest(options: IRequestOptions): IRawRequestFunction {
1515
export class RequestMainService extends NodeRequestService {
1616

1717
override request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
18-
return super.request({ ...(options || {}), getRawRequest }, token);
18+
return super.request({ ...(options || {}), getRawRequest, isChromiumNetwork: true }, token);
1919
}
2020
}

src/vs/platform/request/node/requestService.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IRawRequestFunction {
2929
export interface NodeRequestOptions extends IRequestOptions {
3030
agent?: Agent;
3131
strictSSL?: boolean;
32+
isChromiumNetwork?: boolean;
3233
getRawRequest?(options: IRequestOptions): IRawRequestFunction;
3334
}
3435

@@ -146,7 +147,12 @@ export class RequestService extends Disposable implements IRequestService {
146147
} else {
147148
let stream: streams.ReadableStreamEvents<Uint8Array> = res;
148149

149-
if (res.headers['content-encoding'] === 'gzip') {
150+
// Responses from Electron net module should be treated as response
151+
// from browser, which will apply gzip filter and decompress the response
152+
// using zlib before passing the result to us. Following step can be bypassed
153+
// in this case and proceed further.
154+
// Refs https://source.chromium.org/chromium/chromium/src/+/main:net/url_request/url_request_http_job.cc;l=1266-1318
155+
if (!options.isChromiumNetwork && res.headers['content-encoding'] === 'gzip') {
150156
stream = res.pipe(createGunzip());
151157
}
152158

@@ -160,6 +166,13 @@ export class RequestService extends Disposable implements IRequestService {
160166
req.setTimeout(options.timeout);
161167
}
162168

169+
// Chromium will abort the request if forbidden headers are set.
170+
// Ref https://source.chromium.org/chromium/chromium/src/+/main:services/network/public/cpp/header_util.cc;l=14-48;
171+
// for additional context.
172+
if (options.isChromiumNetwork) {
173+
req.removeHeader('Content-Length');
174+
}
175+
163176
if (options.data) {
164177
if (typeof options.data === 'string') {
165178
req.write(options.data);

0 commit comments

Comments
 (0)