forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
222 lines (199 loc) · 5.45 KB
/
Copy pathproxy.js
File metadata and controls
222 lines (199 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
/**
* @fileoverview Defines functions for configuring a webdriver proxy:
*
* const proxy = require('selenium-webdriver/proxy');
* const {Capabilities} = require('selenium-webdriver');
*
* let capabilities = new Capabilities();
* capabilities.setProxy(proxy.manual({http: 'host:1234'});
*/
'use strict'
/**
* Supported {@linkplain Config proxy configuration} types.
*
* @enum {string}
*/
const Type = {
AUTODETECT: 'autodetect',
DIRECT: 'direct',
MANUAL: 'manual',
PAC: 'pac',
SYSTEM: 'system',
}
/**
* Describes how a proxy should be configured for a WebDriver session.
* @record
*/
function Config() {}
/**
* The proxy type.
* @type {Type}
*/
Config.prototype.proxyType
/**
* Describes how to configure a PAC proxy.
* @record
* @extends {Config}
*/
function PacConfig() {}
/**
* URL for the PAC file to use.
*
* @type {string}
*/
PacConfig.prototype.proxyAutoconfigUrl
/**
* Record object that defines a manual proxy configuration. Manual
* configurations can be easily created using either the
* {@link ./proxy.manual proxy.manual()} or {@link ./proxy.socks proxy.socks()}
* factory method.
*
* @record
* @extends {Config}
*/
function ManualConfig() {}
/**
* The proxy host for FTP requests.
*
* @type {(string|undefined)}
*/
ManualConfig.prototype.ftpProxy
/**
* The proxy host for HTTP requests.
*
* @type {(string|undefined)}
*/
ManualConfig.prototype.httpProxy
/**
* An array of hosts which should bypass all proxies.
*
* @type {(Array<string>|undefined)}
*/
ManualConfig.prototype.noProxy
/**
* The proxy host for HTTPS requests.
*
* @type {(string|undefined)}
*/
ManualConfig.prototype.sslProxy
/**
* Defines the host and port for the SOCKS proxy to use.
*
* @type {(number|undefined)}
*/
ManualConfig.prototype.socksProxy
/**
* Defines the SOCKS proxy version. Must be a number in the range [0, 255].
*
* @type {(number|undefined)}
*/
ManualConfig.prototype.socksVersion
// PUBLIC API
/** @const */ exports.Config = Config
/** @const */ exports.ManualConfig = ManualConfig
/** @const */ exports.PacConfig = PacConfig
/** @const */ exports.Type = Type
/**
* Configures WebDriver to bypass all browser proxies.
* @return {!Config} A new proxy configuration object.
*/
function direct() {
return { proxyType: Type.DIRECT }
}
/**
* Manually configures the browser proxy. The following options are
* supported:
*
* - `ftp`: Proxy host to use for FTP requests
* - `http`: Proxy host to use for HTTP requests
* - `https`: Proxy host to use for HTTPS requests
* - `bypass`: A list of hosts requests should directly connect to,
* bypassing any other proxies for that request. May be specified as a
* comma separated string, or a list of strings.
*
* Behavior is undefined for FTP, HTTP, and HTTPS requests if the
* corresponding key is omitted from the configuration options.
*
* @param {{ftp: (string|undefined),
* http: (string|undefined),
* https: (string|undefined),
* bypass: (Array<string>|undefined)}} options Proxy
* configuration options.
* @return {!ManualConfig} A new proxy configuration object.
*/
function manual({ ftp, http, https, bypass }) {
return {
proxyType: Type.MANUAL,
ftpProxy: ftp,
httpProxy: http,
sslProxy: https,
noProxy: bypass,
}
}
/**
* Creates a proxy configuration for a socks proxy.
*
* __Example:__
*
* const {Capabilities} = require('selenium-webdriver');
* const proxy = require('selenium-webdriver/lib/proxy');
*
* let capabilities = new Capabilities();
* capabilities.setProxy(proxy.socks('localhost:1234'));
*
* // Or, to include authentication.
* capabilities.setProxy(proxy.socks('bob:password@localhost:1234'));
*
*
* @param {string} socksProxy The proxy host, in the form `hostname:port`.
* @param {number=} socksVersion The SOCKS proxy version.
* @return {!ManualConfig} A new proxy configuration object.
* @see https://en.wikipedia.org/wiki/SOCKS
*/
function socks(socksProxy, socksVersion = undefined) {
return /** @type {!Config} */ ({
proxyType: Type.MANUAL,
socksProxy,
socksVersion,
})
}
/**
* Configures WebDriver to configure the browser proxy using the PAC file at
* the given URL.
* @param {string} proxyAutoconfigUrl URL for the PAC proxy to use.
* @return {!PacConfig} A new proxy configuration object.
*/
function pac(proxyAutoconfigUrl) {
return { proxyType: Type.PAC, proxyAutoconfigUrl }
}
/**
* Configures WebDriver to use the current system's proxy.
* @return {!Config} A new proxy configuration object.
*/
function system() {
return { proxyType: Type.SYSTEM }
}
// PUBLIC API
module.exports = {
system,
pac,
socks,
manual,
direct,
}