@@ -29,6 +29,7 @@ export interface IRawRequestFunction {
29
29
export interface NodeRequestOptions extends IRequestOptions {
30
30
agent ?: Agent ;
31
31
strictSSL ?: boolean ;
32
+ isChromiumNetwork ?: boolean ;
32
33
getRawRequest ?( options : IRequestOptions ) : IRawRequestFunction ;
33
34
}
34
35
@@ -146,7 +147,12 @@ export class RequestService extends Disposable implements IRequestService {
146
147
} else {
147
148
let stream : streams . ReadableStreamEvents < Uint8Array > = res ;
148
149
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' ) {
150
156
stream = res . pipe ( createGunzip ( ) ) ;
151
157
}
152
158
@@ -160,6 +166,13 @@ export class RequestService extends Disposable implements IRequestService {
160
166
req . setTimeout ( options . timeout ) ;
161
167
}
162
168
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
+
163
176
if ( options . data ) {
164
177
if ( typeof options . data === 'string' ) {
165
178
req . write ( options . data ) ;
0 commit comments