|
| 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 | +}; |
0 commit comments