@@ -4,9 +4,13 @@ var https = require('https'),
4
4
path = require ( 'path' ) ,
5
5
os = require ( 'os' ) ,
6
6
childProcess = require ( 'child_process' ) ,
7
+ zlib = require ( 'zlib' ) ,
7
8
HttpsProxyAgent = require ( 'https-proxy-agent' ) ,
9
+ version = require ( '../package.json' ) . version ,
8
10
LocalError = require ( './LocalError' ) ;
9
11
12
+ const packageName = 'browserstack-local-nodejs' ;
13
+
10
14
function LocalBinary ( ) {
11
15
this . hostOS = process . platform ;
12
16
this . is64bits = process . arch == 'x64' ;
@@ -81,7 +85,9 @@ function LocalBinary(){
81
85
}
82
86
83
87
try {
84
- const obj = childProcess . spawnSync ( cmd , opts ) ;
88
+ const userAgent = [ packageName , version ] . join ( '/' ) ;
89
+ const env = Object . assign ( { 'USER_AGENT' : userAgent } , process . env ) ;
90
+ const obj = childProcess . spawnSync ( cmd , opts , { env : env } ) ;
85
91
let output ;
86
92
if ( obj . stdout . length > 0 ) {
87
93
if ( fs . existsSync ( binaryPath ) ) {
@@ -122,12 +128,23 @@ function LocalBinary(){
122
128
try {
123
129
options . ca = fs . readFileSync ( conf . useCaCertificate ) ;
124
130
} catch ( err ) {
125
- console . log ( " failed to read cert file" , err )
131
+ console . log ( ' failed to read cert file' , err ) ;
126
132
}
127
133
}
128
134
135
+ options . headers = Object . assign ( { } , options . headers , {
136
+ 'accept-encoding' : 'gzip, *' ,
137
+ 'user-agent' : [ packageName , version ] . join ( '/' ) ,
138
+ } ) ;
139
+
129
140
https . get ( options , function ( response ) {
130
- response . pipe ( fileStream ) ;
141
+ const contentEncoding = response . headers [ 'content-encoding' ] ;
142
+ if ( typeof contentEncoding === 'string' && contentEncoding . match ( / g z i p / i) ) {
143
+ response . pipe ( zlib . createGunzip ( ) ) . pipe ( fileStream ) ;
144
+ } else {
145
+ response . pipe ( fileStream ) ;
146
+ }
147
+
131
148
response . on ( 'error' , function ( err ) {
132
149
console . error ( 'Got Error in binary download response' , err ) ;
133
150
that . retryBinaryDownload ( conf , destParentDir , callback , retries , binaryPath ) ;
0 commit comments