Skip to content

Commit 6106c78

Browse files
akhillbjleyba
authored andcommitted
Add builder api for setting http agent for each request
Signed-off-by: Jason Leyba <[email protected]>
1 parent cfbcbd6 commit 6106c78

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v2.54.0-dev
2+
3+
* Allow users to set the agent used for HTTP connections through
4+
`builder.Builder#usingHttpAgent()`
5+
16
## v2.53.2
27

38
* Changed `io.exists()` to return a rejected promise if the input path is not

javascript/node/selenium-webdriver/builder.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class Builder {
128128

129129
/** @private {boolean} */
130130
this.ignoreEnv_ = false;
131+
132+
/** @private {http.Agent} */
133+
this.agent_ = null;
131134
}
132135

133136
/**
@@ -187,6 +190,25 @@ class Builder {
187190
return this.proxy_;
188191
}
189192

193+
/**
194+
* Sets the http agent to use for each request.
195+
* If this method is not called, the Builder will use http.globalAgent by default.
196+
*
197+
* @param {http.Agent} agent The agent to use for each request.
198+
* @return {!Builder} A self reference.
199+
*/
200+
usingHttpAgent(agent) {
201+
this.agent_ = agent;
202+
return this;
203+
}
204+
205+
/**
206+
* @return {http.Agent} The http agent used for each request
207+
*/
208+
getHttpAgent() {
209+
return this.agent_;
210+
}
211+
190212
/**
191213
* Sets the desired capabilities when requesting a new session. This will
192214
* overwrite any previously set capabilities.
@@ -454,7 +476,7 @@ class Builder {
454476
}
455477

456478
if (url) {
457-
var executor = executors.createExecutor(url, this.proxy_);
479+
var executor = executors.createExecutor(url, this.agent_, this.proxy_);
458480
return WebDriver.createSession(executor, capabilities, this.flow_);
459481
}
460482

javascript/node/selenium-webdriver/executors.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ exports.DeferredExecutor = DeferredExecutor;
3838
* Creates a command executor that uses WebDriver's JSON wire protocol.
3939
* @param {(string|!promise.Promise<string>)} url The server's URL,
4040
* or a promise that will resolve to that URL.
41-
* @param {?string=} opt_proxy (optional) The URL of the HTTP proxy for the
42-
* client to use.
41+
* @param {http.Agent=} opt_agent (optional) The Http.Agent for the client to
42+
* use.
43+
* @param {(string|null)=} opt_proxy (optional) The URL of the HTTP proxy for
44+
* the client to use.
4345
* @returns {!./lib/command.Executor} The new command executor.
4446
*/
45-
exports.createExecutor = function(url, opt_proxy) {
47+
exports.createExecutor = function(url, opt_agent, opt_proxy) {
4648
return new DeferredExecutor(promise.when(url, function(url) {
47-
var client = new HttpClient(url, null, opt_proxy);
49+
var client = new HttpClient(url, opt_agent, opt_proxy);
4850
return new HttpExecutor(client);
4951
}));
5052
};

javascript/node/selenium-webdriver/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-webdriver",
3-
"version": "2.53.2",
3+
"version": "2.54.0-dev",
44
"description": "The official WebDriver JavaScript bindings from the Selenium project",
55
"license": "Apache-2.0",
66
"keywords": [

0 commit comments

Comments
 (0)