Skip to content

Commit bc61af4

Browse files
committed
Merge pull request #74 from browserstack/proxy_support
Proxy support
2 parents 8d59e9b + 0bef6b7 commit bc61af4

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ Identifier for the current instance of the tunnel process. In `TRAVIS` setup `TR
137137
* `BROWSERSTACK_JSON`:
138138
Path to the browserstack.json file. If null, `browserstack.json` in the root directory will be used.
139139

140+
### Proxy support for BrowserStack local
141+
Add the following in `browserstack.json`
142+
```json
143+
...
144+
"proxy": {
145+
"host": "localhost",
146+
"port": 3128,
147+
"username": "foo",
148+
"password": "bar"
149+
}
150+
...
151+
```
140152

141153
### Secure Information
142154

bin/cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ var Log = require('../lib/logger'),
1919
utils = require('../lib/utils'),
2020
Server = require('../lib/server').Server,
2121
Tunnel = require('../lib/local').Tunnel,
22+
tunnel = require('tunnel'),
23+
http = require('http'),
2224
ConfigParser = require('../lib/configParser').ConfigParser,
2325
serverPort = 8888,
2426
timeout,
2527
activityTimeout,
2628
workers = {},
2729
workerKeys = {},
2830
logLevel,
31+
tunnelingAgent,
2932
tunnel;
3033

3134
function terminateAllWorkers(callback) {
@@ -253,6 +256,16 @@ var statusPoller = {
253256
};
254257

255258
function runTests() {
259+
if (config.proxy) {
260+
tunnelingAgent = tunnel.httpOverHttp({
261+
proxy: config.proxy
262+
});
263+
var oldhttpreq = http.request;
264+
http.request = function (options, callback) {
265+
options.agent = tunnelingAgent;
266+
return oldhttpreq.call(null, options, callback);
267+
};
268+
}
256269
if (config.browsers && config.browsers.length > 0) {
257270
ConfigParser.parse(client, config.browsers, function(browsers){
258271
launchServer();

lib/local.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, callback, err) {
1919
tunnelCommand += port.toString() + ',';
2020
tunnelCommand += '0';
2121
tunnelCommand += (typeof uniqueIdentifier === 'undefined') ? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + uniqueIdentifier;
22+
tunnelCommand += checkAndAddProxy();
2223

2324
if (typeof callback !== 'function') {
2425
callback = function(){};
@@ -62,6 +63,21 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, callback, err) {
6263
that.process = subProcess;
6364
}
6465

66+
function checkAndAddProxy() {
67+
var proxy = config.proxy;
68+
if(typeof proxy == 'undefined') {
69+
return "";
70+
}
71+
var proxyCommand = "";
72+
proxyCommand += " -proxyHost " + proxy.host;
73+
proxyCommand += " -proxyPort " + proxy.port;
74+
if(typeof proxy.username !== 'undefined'){
75+
proxyCommand += " -proxyUser " + proxy.username;
76+
proxyCommand += " -proxyPass " + proxy.password;
77+
}
78+
return proxyCommand;
79+
}
80+
6581
fs.exists(localBinary, function(exists) {
6682
if (exists) {
6783
tunnelLauncher();

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"dependencies": {
1111
"browserstack": "1.0.1",
12-
"chalk": "0.4.0"
12+
"chalk": "0.4.0",
13+
"tunnel": "0.0.3"
1314
},
1415
"licenses": [
1516
{

0 commit comments

Comments
 (0)