Skip to content

Commit

Permalink
Add https proxy support
Browse files Browse the repository at this point in the history
To access "api.browserstack.com" behind a proxy it is needed to add a
https proxy.

Ref #39
Ref #45
  • Loading branch information
Teun van de Merwe authored and scottgonzalez committed Apr 21, 2016
1 parent f66d857 commit 70b79c5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function ApiBaseClient(settings) {
this.server = {
host: "api.browserstack.com"
};
this.proxy = settings.proxy || null;
BaseClient.call(this, settings);
}

Expand Down
6 changes: 5 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var https = require("https");
var http = require("http");
var extend = require("./extend");
var HttpsProxyAgent = require('https-proxy-agent');
var userAgent = getUA();

function getUA() {
Expand Down Expand Up @@ -34,6 +35,8 @@ BaseClient.prototype.request = function(options, data, fn) {

fn = fn || function() {};

var agent = (this.proxy) ? new HttpsProxyAgent(this.proxy) : null;

var reqOptions = extend({
host: this.server.host,
port: this.server.port,
Expand All @@ -43,7 +46,8 @@ BaseClient.prototype.request = function(options, data, fn) {
"content-type": "application/json",
"user-agent": userAgent,
"content-length": typeof data === "string" ? data.length : 0
}
},
agent: agent
}, options);

var req = (this.useHttp ? http : https).request(reqOptions, function(res) {
Expand Down
1 change: 1 addition & 0 deletions lib/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function ScreenshotClient(settings) {
this.server = {
host: "www.browserstack.com"
};
this.proxy = settings.proxy || null;
BaseClient.call(this, settings);
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
},
"bugs": "https://github.com/scottgonzalez/node-browserstack/issues",
"licence": "MIT",
"dependencies": {},
"dependencies": {
"https-proxy-agent": "1.0.0"
},
"devDependencies": {
"jscs": "2.8.0",
"jshint": "2.8.0",
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ npm install browserstack
var BrowserStack = require("browserstack");
var browserStackCredentials = {
username: "foo",
password: "p455w0rd!!1"
password: "p455w0rd!!1",
https_proxy: "http://optional.proxy:1234"
};

// REST API
Expand All @@ -36,6 +37,7 @@ automateClient.getBrowsers(function(error, browsers) {
});

// Screenshots API

var screenshotClient = BrowserStack.createScreenshotClient(browserStackCredentials);

screenshotClient.getBrowsers(function(error, browsers) {
Expand Down Expand Up @@ -154,6 +156,7 @@ Creates a new client instance.
* `password`: The password for the BrowserStack account.
* `version` (optional; default: `4`): Which version of the BrowserStack API to use.
* `server` (optional; default: `{ host: "api.browserstack.com", port: 80 }`): An object containing `host` and `port` to connect to a different BrowserStack API compatible service.
* `proxy` (optional; default: `null`): "http://myproxy.com:1234"

#### client.getBrowsers(callback)

Expand Down

0 comments on commit 70b79c5

Please sign in to comment.