Enterprise IT Administrator IE11 Upgrade Guide "15"--Proxy Auto-configuration script

Source: Internet
Author: User

Enterprise IT Administrator IE11 Upgrade Guide series:

"1"--internet Explorer 11 Enhanced Protected Mode (EPM) Introduction

"2"--internet Explorer 11 support for Adobe Flash

"3"--ie11 new GPO settings

Introduction of "4"--ie Enterprise model

"5"--No Tracking (DNT) exception

"6"--internet Explorer 11 FAQ for IT Pros

Comparison of IE11 functions on "7"--win7 and Win8.1

"8"--win7 IE8 and Win7 IE11 contrast

Comparison of the functions of "9"--ie10 and IE11

"10"--How to prevent the installation of IE11

"11"-Deploying Internet Explorer 11 through SCCM 2012 and WSUS

"12"--Compatibility View list Introduction

"13"--How to migrate iemp to GPP

"14"--IE11 Proxy server Configuration

"15"--Proxy automatic configuration script

"16"--use Compat inspector to quickly locate IE compatibility issues

Proxy automatic configuration script

Contents

Brief introduction... 2

Design Tips ... 2

Handle case ... 2

Effective use of indentation ... 3

Handling localhost and loopback addresses ... 3

Block websites via PAC ... 3

Rational use of variables ... 3

Careful use of isinnet, Isresolveable, Dnsresolve method ... 4

IE PAC Result Cache ... 4

Use substrings. 4

Distinguish between text and numeric. 5

Load Balancer Proxy. 5

Debugging... 6

Local PAC test ... 6

Debug with alert () ... 6

To debug the PAC method as an HTML page ... 7

PAC File Download ... 7

Reference... 7

Brief introduction

Proxy Auto-configuration (proxy auto-config, referred to as PAC) is a Web browser technology that defines how the browser automatically chooses the appropriate proxy server to access a URL.

A PAC file contains a JavaScript-form function "FindProxyForURL (URL, host)". This function returns a string that contains one or more access rules. The user agent applies a specific proxy to its or direct access according to these rules. When a proxy server is unable to respond, multiple access rules provide additional fallback access methods. The browser accesses this PAC file first before accessing other pages. The URL in the PAC file may be configured manually or automatically via the Web Proxy Self-Discovery Protocol (Web Proxy AutoDiscovery Protocol) of the webpage.

To use a PAC, we should publish a PAC file on a Web server and use the file by entering the URL of the PAC file in the browser's proxy link settings page or by using the WPAD protocol to inform the user agent.

A PAC file is a text file that defines at least one JavaScript function. This function FindProxyForURL (URL, host) has 2 parameters: The URL is an object url,host is a host name derived from this URL. By convention, the name of this file is generally proxy.pac. The WPAD standard uses Wpad.dat.

Although most clients can handle everything correctly regardless of the MIME type returned from the HTTP request, for completeness and best compatibility, we should set the Web server to declare the MIME type of this file as Application/x-ns-proxy-autoconfig or Application/x-javascript-config.

There is no reason to prefer a MIME type more, if any, it is understandable to assume that the Application/x-ns-proxy-autoconfig relative application/x-javascript-config is supported by more clients. Because it is defined in the original Netscape specification, the latter is only recently started to be used.

A very simple PAC file content

function FindProxyForURL (URL, host) {         return "PROXY proxy.example.com:8080; DIRECT "; }

Design Tips

Handling case

Some browsers are case sensitive, such as www.microsoft.com and WWW.MICROSOFT.COM are considered different hosts. If you want to ignore case, you can usually use it after you convert the argument to lowercase.

var lhost = Host.tolowercase ();
host = Lhost;

Effective use of indentation

Effective use of indentation can improve the readability and maintainability of a PAC file, and for indenting a simple rule is to indent a tab after the curly brace, aligning the matching curly braces.

Handling localhost and loopback addresses

The LocalHost and loopback address (127.0.0.1) should skip the proxy directly, and you can refer to the following logic.

if (host = = "localhost") | |    (shExpMatch (Host, "localhost.*")) | |    (host = = "127.0.0.1")) {       return "DIRECT";}

Blocking websites with PAC

A PAC file makes it easy to block a Web site by simply returning a loopback address so that the request cannot be sent out, which can also save the bandwidth between the client and the agent. The only thing to note is not to send the request to a port that is listening locally.

if (dnsDomainIs (Host, ". badspyware.com") | |    dnsDomainIs (Host, ". worsespyware2.com")) {return "PROXY 127.0.0.1:48890";}

Rational use of variables

Reasonable definition of variables in a PAC file can optimize execution efficiency and increase code readability. For example, to cache a local IP address by defining the variable Myip in the following way, avoid calling the same method every time to query the local IP.

Myip = myIpAddress ();

Another common use is to define variables for the proxy that will be returned, and then change them as the program logic does.

function FindProxyForURL (URL, host) {//Set the default proxy variable that users get if they don ' t match//any more speci FIC rule. Proxy = "proxy coreproxy.company.com:8000";//Los Angeles WAN subnets go to LA PROXY if (isInNet (myIpAddress (), "10.100.0. 0 "," 255.252.0.0 ")) {      proxy =" proxy la-proxy.company.com:8000 ";}//New York WAN subnets go to New York proxy if (IsI Nnet (myIpAddress (), "10.200.0.0", "255.252.0.0")) {      proxy = "proxy ny-proxy.company.com:8000";}

When dealing with proxy in the above way, the most common case is processed first, then the special case is processed, and finally the current value of the proxy is returned to the browser.

return proxy;

Careful use of isinnet, Isresolveable, Dnsresolve method

Many PAC developers often use isInNet (host, "a.b.c.d") to be in an IP segment, but the invocation of the method causes the browser to send a DNS reverse query request for each host name. If many clients in a network are sending similar requests, the load on the DNS server is greatly increased.

IE PAC Result Cache

The PAC processing of IE has a large difference from other browsers, that is, IE will cache the results of PAC processing, that is, it can be thought that it is only executed once for each Host,pac file, until the next restart of IE will be re-executed. This causes some PAC logic to appear to not work properly, such as the need to return different proxies through non-host information in the URL.

The IE PAC results cache can be disabled by the following registry

HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
Value:enableautoproxyresultcache
Type:reg_dword
Data value:0 = disable caching; 1 (or key not present) = Enable automatic proxy caching (this is the default behavior)

Using substrings

As with normal JavaScript methods, you can handle different logic by using substring to determine whether some strings in the URL or host meet certain conditions, and a more common use is to determine which protocol the URL is using and then return the different proxies.

if (url.substring (0,4) = = "http") {return "PROXY http-proxy.company.com:8000";}  Matches HTTP and HTTPS Urlsif (url.substring (0,3) = = "ftp")  {return "PROXY ftp-proxy.company.com:8000";}  Matches ftp://Linksif (url.substring (0,3) = = "MMS") {return "PROXY http-proxy.company.com:8000";}  Matches MMS Links

Distinguish between text and numeric

Note the difference between a string type and a numeric type, such as "92" is a string, and if you need to make it into a numeric type, you need to call the parseint method.

numvariable = parseint (Textvar);

Load Balancer Proxy

Many agencies have multiple proxy servers, but the proxy server is not load-managed through a load balancer. A PAC file allows simple load balancing through client logic.

Find the 4th Octetvar myip=myipaddress () var ipbits=myip.split (".") var myseg=parseint (ipbits[3])//Check to see if the 4th Octect is even or oddif (Myseg==math.floor (MYSEG/2) * *) {     //Ev En      proxy = "proxy p1.company.com:8080; PROXY p2.company.com:8080 ";} else {     //Odd     proxy = "proxy p2.company.com:8080; PROXY p1.company.com:8080 ";}

Debugging

The preparation of PAC files will inevitably require testing and debugging, for example, when you write a JavaScript syntax error, or some methods return unexpected results. Many browsers do not provide support for PAC script debugging, and some techniques are required for PAC file debugging.

Local PAC Test

In some cases, the PAC file does not seem to work at all, and we can test it by downloading the PAC file locally and accessing the PAC file by means of a local file.

Note Local PAC files are disabled by default in IE11, and local PAC file tests require that the following registry key be changed.

Key:hklm\software\policies\microsoft\windows\currentversion\internet Settings\
Value:enablelegacyautoproxyfeatures
Type:reg_dword
Data:1

Debug with alert ()

By adding the alert () method, you can effectively help with debugging, for example, myipaddress () Gets an incorrect address, and the alert method makes it easy to find similar problems.

if ((host = = "Proxyinfo.company.com")) {
Alert ("Local IP address is:" + myipaddress ());
}

Alert can also help locate script syntax errors, such as alert on different logical paths, four dialogs in the right case, but only three pops up, so we can tell that there may be a syntax error between the third and fourth alert.

To debug the Pac method as in the HTML page

The function FindProxyForURL (URL, host) method of the PAC file is placed in an HTML page and then opened through the browser, which makes it easy to find syntax errors in the script.

PAC File download

Since PAC files are usually placed on a Web server, a common problem is to download the problem, to determine whether there is a PAC file download problem, you can directly enter the PAC address through the browser to try to download to see if it can be downloaded successfully.

Reference

Http://en.wikipedia.org/wiki/Proxy_auto-config

http://www.proxypacfiles.com/proxypac/

http://technet.microsoft.com/library/Dd361918

http://findproxyforurl.com/

http://support.microsoft.com/kb/271361

Enterprise IT Administrator IE11 Upgrade Guide "15"--Proxy Auto-configuration script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.