Skip to content

Commit b824de0

Browse files
odduijleyba
authored andcommitted
Change proxy to not depend on node util module (#2391)
* change util.isArray to Array.isArray * move proxy.js into lib
1 parent 74c5a85 commit b824de0

File tree

2 files changed

+101
-75
lines changed

2 files changed

+101
-75
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
/**
19+
* @fileoverview Defines functions for configuring a webdriver proxy:
20+
*
21+
* const Capabilities = require('./capabilities').Capabilities;
22+
*
23+
* var capabilities = new Capabilities();
24+
* capabilities.setProxy(proxy.manual({http: 'host:1234'});
25+
*/
26+
27+
'use strict';
28+
29+
var ProxyConfig = require('./capabilities').ProxyConfig;
30+
31+
32+
// PUBLIC API
33+
34+
35+
/**
36+
* Configures WebDriver to bypass all browser proxies.
37+
* @return {!ProxyConfig} A new proxy configuration object.
38+
*/
39+
exports.direct = function() {
40+
return {proxyType: 'direct'};
41+
};
42+
43+
44+
/**
45+
* Manually configures the browser proxy. The following options are
46+
* supported:
47+
*
48+
* - `ftp`: Proxy host to use for FTP requests
49+
* - `http`: Proxy host to use for HTTP requests
50+
* - `https`: Proxy host to use for HTTPS requests
51+
* - `bypass`: A list of hosts requests should directly connect to,
52+
* bypassing any other proxies for that request. May be specified as a
53+
* comma separated string, or a list of strings.
54+
*
55+
* Behavior is undefined for FTP, HTTP, and HTTPS requests if the
56+
* corresponding key is omitted from the configuration options.
57+
*
58+
* @param {{ftp: (string|undefined),
59+
* http: (string|undefined),
60+
* https: (string|undefined),
61+
* bypass: (string|!Array.<string>|undefined)}} options Proxy
62+
* configuration options.
63+
* @return {!ProxyConfig} A new proxy configuration object.
64+
*/
65+
exports.manual = function(options) {
66+
// TODO(jleyba): Figure out why the Closure compiler does not think this is
67+
// a ProxyConfig record without the cast.
68+
return /** @type {!ProxyConfig} */({
69+
proxyType: 'manual',
70+
ftpProxy: options.ftp,
71+
httpProxy: options.http,
72+
sslProxy: options.https,
73+
noProxy: Array.isArray(options.bypass) ?
74+
options.bypass.join(',') : options.bypass
75+
});
76+
};
77+
78+
79+
/**
80+
* Configures WebDriver to configure the browser proxy using the PAC file at
81+
* the given URL.
82+
* @param {string} url URL for the PAC proxy to use.
83+
* @return {!ProxyConfig} A new proxy configuration object.
84+
*/
85+
exports.pac = function(url) {
86+
return {
87+
proxyType: 'pac',
88+
proxyAutoconfigUrl: url
89+
};
90+
};
91+
92+
93+
/**
94+
* Configures WebDriver to use the current system's proxy.
95+
* @return {!ProxyConfig} A new proxy configuration object.
96+
*/
97+
exports.system = function() {
98+
return {proxyType: 'system'};
99+
};

javascript/node/selenium-webdriver/proxy.js

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
/**
19-
* @fileoverview Defines functions for configuring a webdriver proxy:
19+
* @fileoverview Proxy module alias.
2020
*
2121
* var webdriver = require('selenium-webdriver'),
2222
* proxy = require('selenium-webdriver/proxy');
@@ -29,77 +29,4 @@
2929

3030
'use strict';
3131

32-
var util = require('util');
33-
34-
var ProxyConfig = require('./lib/capabilities').ProxyConfig;
35-
36-
37-
38-
// PUBLIC API
39-
40-
41-
/**
42-
* Configures WebDriver to bypass all browser proxies.
43-
* @return {!ProxyConfig} A new proxy configuration object.
44-
*/
45-
exports.direct = function() {
46-
return {proxyType: 'direct'};
47-
};
48-
49-
50-
/**
51-
* Manually configures the browser proxy. The following options are
52-
* supported:
53-
*
54-
* - `ftp`: Proxy host to use for FTP requests
55-
* - `http`: Proxy host to use for HTTP requests
56-
* - `https`: Proxy host to use for HTTPS requests
57-
* - `bypass`: A list of hosts requests should directly connect to,
58-
* bypassing any other proxies for that request. May be specified as a
59-
* comma separated string, or a list of strings.
60-
*
61-
* Behavior is undefined for FTP, HTTP, and HTTPS requests if the
62-
* corresponding key is omitted from the configuration options.
63-
*
64-
* @param {{ftp: (string|undefined),
65-
* http: (string|undefined),
66-
* https: (string|undefined),
67-
* bypass: (string|!Array.<string>|undefined)}} options Proxy
68-
* configuration options.
69-
* @return {!ProxyConfig} A new proxy configuration object.
70-
*/
71-
exports.manual = function(options) {
72-
// TODO(jleyba): Figure out why the Closure compiler does not think this is
73-
// a ProxyConfig record without the cast.
74-
return /** @type {!ProxyConfig} */({
75-
proxyType: 'manual',
76-
ftpProxy: options.ftp,
77-
httpProxy: options.http,
78-
sslProxy: options.https,
79-
noProxy: util.isArray(options.bypass) ?
80-
options.bypass.join(',') : options.bypass
81-
});
82-
};
83-
84-
85-
/**
86-
* Configures WebDriver to configure the browser proxy using the PAC file at
87-
* the given URL.
88-
* @param {string} url URL for the PAC proxy to use.
89-
* @return {!ProxyConfig} A new proxy configuration object.
90-
*/
91-
exports.pac = function(url) {
92-
return {
93-
proxyType: 'pac',
94-
proxyAutoconfigUrl: url
95-
};
96-
};
97-
98-
99-
/**
100-
* Configures WebDriver to use the current system's proxy.
101-
* @return {!ProxyConfig} A new proxy configuration object.
102-
*/
103-
exports.system = function() {
104-
return {proxyType: 'system'};
105-
};
32+
module.exports = require('./lib/proxy');

0 commit comments

Comments
 (0)