1
1
var https = require ( 'https' ) ,
2
+ url = require ( 'url' ) ,
2
3
fs = require ( 'fs' ) ,
3
4
path = require ( 'path' ) ,
4
5
os = require ( 'os' ) ,
6
+ HttpsProxyAgent = require ( 'https-proxy-agent' ) ,
5
7
LocalError = require ( './LocalError' ) ;
6
8
7
9
function LocalBinary ( ) {
@@ -20,15 +22,23 @@ function LocalBinary(){
20
22
this . httpPath = 'https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-linux-ia32' ;
21
23
}
22
24
23
- this . download = function ( destParentDir , callback ) {
25
+ this . download = function ( conf , destParentDir , callback ) {
24
26
if ( ! this . checkPath ( destParentDir ) )
25
27
fs . mkdirSync ( destParentDir ) ;
26
28
27
29
var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
28
30
var binaryPath = path . join ( destParentDir , destBinaryName ) ;
29
31
var file = fs . createWriteStream ( binaryPath ) ;
30
32
31
- https . get ( this . httpPath , function ( response ) {
33
+ var options = url . parse ( this . httpPath ) ;
34
+ if ( conf . proxyHost && conf . proxyPort ) {
35
+ options . agent = new HttpsProxyAgent ( {
36
+ host : conf . proxyHost ,
37
+ port : conf . proxyPort
38
+ } ) ;
39
+ }
40
+
41
+ https . get ( options , function ( response ) {
32
42
response . on ( 'end' , function ( ) {
33
43
fs . chmod ( binaryPath , '0755' , function ( ) {
34
44
callback ( binaryPath ) ;
@@ -38,14 +48,14 @@ function LocalBinary(){
38
48
} ) ;
39
49
} ;
40
50
41
- this . binaryPath = function ( callback ) {
51
+ this . binaryPath = function ( conf , callback ) {
42
52
var destParentDir = this . getAvailableDirs ( ) ;
43
53
var destBinaryName = ( this . windows ) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal' ;
44
54
var binaryPath = path . join ( destParentDir , destBinaryName ) ;
45
55
if ( this . checkPath ( binaryPath , fs . X_OK ) ) {
46
56
callback ( binaryPath ) ;
47
57
} else {
48
- this . download ( destParentDir , callback ) ;
58
+ this . download ( conf , destParentDir , callback ) ;
49
59
}
50
60
} ;
51
61
0 commit comments