Skip to content

Commit

Permalink
fix: main request service for Electron.net requests (microsoft#167075)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 authored Nov 24, 2022
1 parent 0306f1e commit 0f8089f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ function getRawRequest(options: IRequestOptions): IRawRequestFunction {
export class RequestMainService extends NodeRequestService {

override request(options: IRequestOptions, token: CancellationToken): Promise<IRequestContext> {
return super.request({ ...(options || {}), getRawRequest }, token);
return super.request({ ...(options || {}), getRawRequest, isChromiumNetwork: true }, token);
}
}
15 changes: 14 additions & 1 deletion src/vs/platform/request/node/requestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IRawRequestFunction {
export interface NodeRequestOptions extends IRequestOptions {
agent?: Agent;
strictSSL?: boolean;
isChromiumNetwork?: boolean;
getRawRequest?(options: IRequestOptions): IRawRequestFunction;
}

Expand Down Expand Up @@ -146,7 +147,12 @@ export class RequestService extends Disposable implements IRequestService {
} else {
let stream: streams.ReadableStreamEvents<Uint8Array> = 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());
}

Expand All @@ -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);
Expand Down

0 comments on commit 0f8089f

Please sign in to comment.