# proxy.js

    1// Copyright 2013 Selenium committers2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5//     You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415/**16 * @fileoverview Defines functions for configuring a webdriver proxy:17 * <pre><code>18 * var webdriver = require('selenium-webdriver'),19 *     proxy = require('selenium-webdriver/proxy');20 *21 * var driver = new webdriver.Builder()22 *     .withCapabilities(webdriver.Capabilities.chrome())23 *     .setProxy(proxy.manual({http: 'host:1234'}))24 *     .build();25 * </code></pre>26 */2728'use strict';2930var util = require('util');31323334// PUBLIC API353637/**38 * Configures WebDriver to bypass all browser proxies.39 * @return {!webdriver.ProxyConfig} A new proxy configuration object.40 */41exports.direct = function() {42  return {proxyType: 'direct'};43};444546/**47 * Manually configures the browser proxy.  The following options are48 * supported:49 * <ul>50 * <li>{@code ftp}: Proxy host to use for FTP requests51 * <li>{@code http}: Proxy host to use for HTTP requests52 * <li>{@code https}: Proxy host to use for HTTPS requests53 * <li>{@code bypass}: A list of hosts requests should directly connect to,54 *     bypassing any other proxies for that request. May be specified as a55 *     comma separated string, or a list of strings.56 * </ul>57 *58 * Behavior is undefined for FTP, HTTP, and HTTPS requests if the59 * corresponding key is omitted from the configuration options.60 *61 * @param {{ftp: (string|undefined),62 *          http: (string|undefined),63 *          https: (string|undefined),64 *          bypass: (string|!Array.<string>|undefined)}} options Proxy65 *     configuration options.66 * @return {!webdriver.ProxyConfig} A new proxy configuration object.67 */68exports.manual = function(options) {69  return {70    proxyType: 'manual',71    ftpProxy: options.ftp,72    httpProxy: options.http,73    sslProxy: options.https,74    noProxy: util.isArray(options.bypass) ?75        options.bypass.join(',') : options.bypass76  };77};787980/**81 * Configures WebDriver to configure the browser proxy using the PAC file at82 * the given URL.83 * @param {string} url URL for the PAC proxy to use.84 * @return {!webdriver.ProxyConfig} A new proxy configuration object.85 */86exports.pac = function(url) {87  return {88    proxyType: 'pac',89    proxyAutoconfigUrl: url90  };91};929394/**95 * Configures WebDriver to use the current system's proxy.96 * @return {!webdriver.ProxyConfig} A new proxy configuration object.97 */98exports.system = function() {99  return {proxyType: 'system'};100};