5
5
6
6
'use strict' ;
7
7
8
- import { Url , parse as parseUrl } from 'url' ;
8
+ import { Url , parse as parseUrl } from 'url' ;
9
9
import https = require( 'https' ) ;
10
10
import http = require( 'http' ) ;
11
11
import HttpProxyAgent = require( 'http-proxy-agent' ) ;
12
12
import HttpsProxyAgent = require( 'https-proxy-agent' ) ;
13
+ import zlib = require( 'zlib' ) ;
13
14
14
15
import * as nls from 'vscode-nls' ;
15
16
nls . config ( process . env [ 'VSCODE_NLS_CONFIG' ] ) ;
@@ -57,9 +58,20 @@ export function xhr(options: XHROptions): Promise<XHRResponse> {
57
58
58
59
return request ( options ) . then ( result => new Promise < XHRResponse > ( ( c , e ) => {
59
60
let res = result . res ;
61
+ let readable : NodeJS . ReadableStream = res ;
62
+ let encoding = res . headers && res . headers [ 'content-encoding' ] ;
63
+ if ( encoding === 'gzip' ) {
64
+ let gunzip = zlib . createGunzip ( ) ;
65
+ res . pipe ( gunzip ) ;
66
+ readable = gunzip ;
67
+ } else if ( encoding === 'deflate' ) {
68
+ let inflate = zlib . createInflate ( ) ;
69
+ res . pipe ( inflate ) ;
70
+ readable = inflate ;
71
+ }
60
72
let data : any = [ ] ;
61
- res . on ( 'data' , c => data . push ( c ) ) ;
62
- res . on ( 'end' , ( ) => {
73
+ readable . on ( 'data' , c => data . push ( c ) ) ;
74
+ readable . on ( 'end' , ( ) => {
63
75
if ( options . followRedirects > 0 && ( res . statusCode >= 300 && res . statusCode <= 303 || res . statusCode === 307 ) ) {
64
76
let location = res . headers [ 'location' ] ;
65
77
if ( location ) {
@@ -131,7 +143,7 @@ function request(options: XHROptions): Promise<RequestResult> {
131
143
132
144
let handler = ( res : http . ClientResponse ) => {
133
145
if ( res . statusCode >= 300 && res . statusCode < 400 && options . followRedirects && options . followRedirects > 0 && res . headers [ 'location' ] ) {
134
- c ( < any > request ( assign ( { } , options , {
146
+ c ( < any > request ( assign ( { } , options , {
135
147
url : res . headers [ 'location' ] ,
136
148
followRedirects : options . followRedirects - 1
137
149
} ) ) ) ;
@@ -158,7 +170,7 @@ function request(options: XHROptions): Promise<RequestResult> {
158
170
} ) ;
159
171
}
160
172
161
- export function getErrorStatusDescription ( status : number ) : string {
173
+ export function getErrorStatusDescription ( status : number ) : string {
162
174
if ( status < 400 ) {
163
175
return void 0 ;
164
176
}
0 commit comments