亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜尋
Guides Access control CORS Authentication Browser detection using the user agent Caching Caching FAQ Compression Conditional requests Connection management in HTTP 1.x Content negotiation Content negotiation: List of default Accept values Cookies CSP Messages Overview Protocol upgrade mechanism Proxy servers and tunneling Proxy servers and tunneling: Proxy Auto-Configuration (PAC) file Public Key Pinning Range requests Redirections Resources and specifications Resources and URIs Response codes Server-Side Access Control Session Guides: Basics Basics of HTTP Choosing between www and non-www URLs Data URIs Evolution of HTTP Identifying resources on the Web MIME Types MIME types: Complete list of MIME types CSP Content-Security-Policy Content-Security-Policy-Report-Only CSP: base-uri CSP: block-all-mixed-content CSP: child-src CSP: connect-src CSP: default-src CSP: font-src CSP: form-action CSP: frame-ancestors CSP: frame-src CSP: img-src CSP: manifest-src CSP: media-src CSP: object-src CSP: plugin-types CSP: referrer CSP: report-uri CSP: require-sri-for CSP: sandbox CSP: script-src CSP: style-src CSP: upgrade-insecure-requests CSP: worker-src Headers Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Access-Control-Allow-Credentials Access-Control-Allow-Headers Access-Control-Allow-Methods Access-Control-Allow-Origin Access-Control-Expose-Headers Access-Control-Max-Age Access-Control-Request-Headers Access-Control-Request-Method Age Allow Authorization Cache-Control Connection Content-Disposition Content-Encoding Content-Language Content-Length Content-Location Content-Range Content-Type Cookie Cookie2 Date DNT ETag Expect Expires Forwarded From Headers Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Keep-Alive Large-Allocation Last-Modified Location Origin Pragma Proxy-Authenticate Proxy-Authorization Public-Key-Pins Public-Key-Pins-Report-Only Range Referer Referrer-Policy Retry-After Server Set-Cookie Set-Cookie2 SourceMap Strict-Transport-Security TE Tk Trailer Transfer-Encoding Upgrade-Insecure-Requests User-Agent User-Agent: Firefox Vary Via Warning WWW-Authenticate X-Content-Type-Options X-DNS-Prefetch-Control X-Forwarded-For X-Forwarded-Host X-Forwarded-Proto X-Frame-Options X-XSS-Protection Methods CONNECT DELETE GET HEAD Methods OPTIONS PATCH POST PUT Status 100 Continue 101 Switching Protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 307 Temporary Redirect 308 Permanent Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Payload Too Large 414 URI Too Long 415 Unsupported Media Type 416 Range Not Satisfiable 417 Expectation Failed 426 Upgrade Required 428 Precondition Required 429 Too Many Requests 431 Request Header Fields Too Large 451 Unavailable For Legal Reasons 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported 511 Network Authentication Required Status
文字

一個代理服務(wù)器自動配置(PAC)文件是一個JavaScript函數(shù),確定網(wǎng)絡(luò)瀏覽器的請求(HTTP,HTTPS和FTP)是否直接去目的地或轉(zhuǎn)發(fā)到Web代理服務(wù)器。包含在PAC文件中的JavaScript函數(shù)定義了這個函數(shù):

function FindProxyForURL(url, host){    // ...}        ret = FindProxyForURL(url, host);

句法

function FindProxyForURL(url, host)

參數(shù)

url正在訪問的URL。https://URL 的路徑和查詢組件被剝離。在Chrome中,您可以通過設(shè)置PacHttpsUrlStrippingEnabled為禁用此功能false,在Firefox中,首選項是network.proxy.autoconfig_url.include_path.host從URL中提取的主機名。這只是為了方便; 它與之間://和第一個:/之后是相同的字符串。端口號不包含在此參數(shù)中。它可以在必要時從URL中提取。

Description

返回描述配置的字符串。該字符串的格式在下面的返回值格式中定義。

返回值格式

  • JavaScript函數(shù)返回單個字符串

  • 如果字符串為空,則不應(yīng)使用代理

  • 該字符串可以包含任意數(shù)量的以分號分隔的構(gòu)建塊:

DIRECTConnections應(yīng)直接進行,而不使用任何代理PROXY _host:port_應(yīng)使用指定的代理SOCKS _host:port_應(yīng)使用指定的SOCKS服務(wù)器

最近的Firefox支持版本也是這樣:

HTTP_host:port_應(yīng)使用指定的代理HTTP_host:port_應(yīng)使用指定的HTTPS代理SOCKS4_host:port_SOCKS5_host:port_應(yīng)使用指定的SOCKS服務(wù)器(具有指定的SOCK版本)

如果有多個以分號分隔的設(shè)置,則將使用最左側(cè)的設(shè)置,直到Firefox無法建立與代理的連接。在那種情況下,下一個值將被使用,等等。

30分鐘后,瀏覽器將自動重試以前無響應(yīng)的代理。額外的嘗試將在一小時后開始,總是在兩次嘗試之間增加30分鐘。

如果所有代理都關(guān)閉,并且沒有指定DIRECT選項,瀏覽器將詢問是否應(yīng)暫時忽略代理,并嘗試直接連接。20分鐘后,瀏覽器會詢問代理是否應(yīng)該重試,再過40分鐘后再詢問。查詢將繼續(xù),總是在查詢之間經(jīng)過的時間增加20分鐘。

例子

PROXY w3proxy.netscape.com:8080; PROXY mozilla.netscape.com:8081一級代理是w3proxy:8080; 如果發(fā)生故障,開始使用mozilla:8081,直到主代理再次出現(xiàn)。PROXY w3proxy.netscape.com:8080; PROXY mozilla.netscape.com:8081; DIRECTSame如上所述,但是如果兩個代理都關(guān)閉了,自動開始直接連接。(在上面的第一個例子中,Netscape會詢問用戶確認是否有直接連接;在這種情況下,沒有用戶干預(yù)。)PROXY w3proxy.netscape.com:8080; SOCKS socks:如果主代理服務(wù)器關(guān)閉,則使用SOCKS。

自動配置文件應(yīng)該保存到一個帶有.pac文件擴展名的文件中:

proxy.pac

而MIME類型設(shè)置為:

application/x-ns-proxy-autoconfig

接下來,您應(yīng)該配置服務(wù)器將.pac文件擴展名映射到MIME類型。

筆記:

  • JavaScript函數(shù)應(yīng)該總是保存到文件中,而不是嵌入到HTML中。

  • 本文末尾的示例已完成。沒有其他語法需要將其保存到文件中并使用它。(當然,必須編輯JavaScript以反映您的網(wǎng)站的域名和/或子網(wǎng)。)

預(yù)定義的功能和環(huán)境

這些函數(shù)可用于構(gòu)建PAC文件:

  • Hostname based conditions

    • isPlainHostName()(about:blank#isPlainHostName(%29)

    • dnsDomainIs()(about:blank#dnsDomainIs(host,%20domain%29)

    • localHostOrDomainIs()(about:blank#localHostOrDomainIs(host,%20hostdom%29)

    • isResolvable()(about:blank#isResolvable(host%29)

    • isInNet()(about:blank#isInNet(host,%20pattern,%20mask%29)

  • Related utility functions

    • dnsResolve()(about:blank#dnsResolve(host%29)

    • convert_addr()(about:blank#convert_addr(%29)

    • myIpAddress()(about:blank#myIpAddress(%29)

    • dnsDomainLevels()(about:blank#dnsDomainLevels(host%29)

  • URL/hostname based conditions

    • shExpMatch()(about:blank#shExpMatch(str,%20shexp%29)

  • Time based conditions

    • weekdayRange()(about:blank#weekdayRange(wd1,%20wd2,%20gmt%29)

    • dateRange()(about:blank#dateRange(%29)

    • timeRange()(about:blank#timeRange(%29)

  • There is one associative array already defined (because a JavaScript currently cannot define them on its own):

    • ProxyConfig.bindings

注意: pactester(pacparser包的一部分)用于測試以下語法示例。

  • The PAC file is named proxy.pac

  • Command line: pactester -p ~/pacparser-master/tests/proxy.pac -u http://www.mozilla.org

    • This command passes the host parameter www.mozilla.org and the url parameter http://www.mozilla.org.

isPlainHostName()

句法

isPlainHostName(host)

參數(shù)

主機URL中的主機名(不包括端口號)。

描述

當且僅當主機名中沒有域名(無點)時才為真。

例子

function FindProxyForURL(url, host) {  if (!isPlainHostName(host))    return host;}//returns "www.mozilla.org"
function FindProxyForURL(url, host) {  if (isPlainHostName("www"))    return "isPlainHostName is true";  return "isPlainHostName is false";}//returns "isPlainHostName is true"

dnsDomainIs()

句法

dnsDomainIs(host, domain)

參數(shù)

主機是來自URL的主機名。域用來測試主機名。

描述

當且僅當主機名的域匹配時返回true。

例子

function FindProxyForURL(url, host) {  if (dnsDomainIs("www.mozilla.org", ".mozilla.org"))    return "dnsDomainIs is true";  return "dnsDomainIs is false";}//returns "dnsDomainIs is true"
function FindProxyForURL(url, host) {  if (dnsDomainIs("www", ".mozilla.org"))    return "dnsDomainIs is true";  return "dnsDomainIs is false";}//returns "dnsDomainIs is false"

localHostOrDomainIs()

句法

localHostOrDomainIs(host, hostdom)

參數(shù)

hosthost從URL.hostdomFully限定的主機名中匹配的主機名。

描述

如果主機名與指定的主機名完全匹配,或者主機名中沒有域名部分,但未匹配的主機名匹配,則為true。

例子

function FindProxyForURL(url, host) {  if (localHostOrDomainIs("www.mozilla.org", "www.mozilla.org"))    return "localHostOrDomainIs is true (exact match)";  return "localHostOrDomainIs is false";}//returns "localHostOrDomainIs is true (exact match)"
function FindProxyForURL(url, host) {  if (localHostOrDomainIs("www", "www.mozilla.org"))    return "localHostOrDomainIs is true (hostname match, domain not specified))";  return "localHostOrDomainIs is false";}//returns "localHostOrDomainIs is true (hostname match, domain not specified))"
function FindProxyForURL(url, host) {  if (localHostOrDomainIs("www.google.com", "www.mozilla.org"))    return "localHostOrDomainIs is true";  return "localHostOrDomainIs is false (domain name mismatch)";} // returns "localHostOrDomainIs is false (domain name mismatch)"
function FindProxyForURL(url, host) {  if (localHostOrDomainIs("home.mozilla.org", "www.mozilla.org"))    return "localHostOrDomainIs is true";  return "localHostOrDomainIs is false (domain name mismatch)"; }// returns "localHostOrDomainIs is false (hostname mismatch)"

isResolvable()

句法

isResolvable(host)

參數(shù)

hostis是URL中的主機名。

嘗試解析主機名。成功返回true。

例子:

function FindProxyForURL(url, host) {  if (isResolvable("www.mozilla.org"))    return "isResolvable is true";  return "isResolvable is false";}// returns "isResolvable is true"

isInNet()

句法

isInNet(host, pattern, mask)

參數(shù)

hosta DNS主機名或IP地址。如果一個主機名被傳遞,它將通過這個函數(shù)被解析為一個IP地址。在IP地址模式中用點分隔的格式.maskmask表示IP地址模式,通知應(yīng)匹配IP地址的哪些部分。0表示忽略,255表示匹配。

當且僅當主機的IP地址與指定的IP地址模式匹配時才為真。

模式和模板規(guī)范的完成方式與SOCKS配置相同。

例子:

function FindProxyForURL(url, host) {// put in the address returned by dnsResolve (see next example)  if (isInNet(host, "63.245.213.24", "255.255.255.255"))    return "isInNet is true";  return "isInNet is false";}// returns "isInNet is true"

dnsResolve()

dnsResolve(host)

參數(shù)

hosthostname來解決。

將給定的DNS主機名解析為IP地址,并以點分隔格式將其作為字符串返回。

function FindProxyForURL(url, host) {  return dnsResolve("www.mozilla.org");} //returns the string "104.16.41.2"

convert_addr()

句法

convert_addr(ipaddr)

參數(shù)

ipaddrAny虛線地址,如IP地址或掩碼。

將四個點分隔的字節(jié)連接成一個4字節(jié)的字并將其轉(zhuǎn)換為十進制。

function FindProxyForURL(url, host) {  return convert_addr("104.16.41.2");} //returns the decimal number 1745889538

myIpAddress()

句法

myIpAddress()

參數(shù)

(none)

以點分隔的整數(shù)格式返回運行Firefox的計算機的服務(wù)器IP地址,作為字符串。

myIpAddress()返回與nslookup localhostLinux機器返回的服務(wù)器地址相同的IP地址。它不返回公共IP地址。

function FindProxyForURL(url, host) {  return myIpAddress();} //returns the string "127.0.1.1" if you were running Firefox on that localhost

dnsDomainLevels()

句法

dnsDomainLevels(host)

參數(shù)

hostis是URL中的主機名。

返回主機名中的DNS域級別(點數(shù))的數(shù)量(整數(shù))。

例子:

function FindProxyForURL(url, host) {  return dnsDomainLevels("www");}//returns 0
function FindProxyForURL(url, host) {  return dnsDomainLevels("mozilla.org");}//returns 1
function FindProxyForURL(url, host) {  return dnsDomainLevels("www.mozilla.org");}//returns 2

shExpMatch()

句法

shExpMatch(str, shexp)

參數(shù)

stris要比較的任何字符串(例如,URL或主機名).shexp是一個shell表達式來比較。

如果字符串匹配指定的shell表達式,則返回true。

目前,這些模式是 shell表達式,而不是正則表達式。

例子

function FindProxyForURL(url, host) {  return shExpMatch("http://home.netscape.com/people/ari/index.html", "*/ari/*");}//returns true
function FindProxyForURL(url, host) {  return shExpMatch("http://home.netscape.com/people/montulli/index.html", "*/ari/*");}//returns false

weekdayRange()

句法

weekdayRange(wd1, wd2, gmt)

注意:(在Firefox 49之前)如果您希望函數(shù)將這些參數(shù)作為范圍進行評估,則wd1必須小于wd2??吹较旅娴木妗?/p>

參數(shù)

有序周日字符串的wd1和wd2One:

"SUN"|"MON"|"TUE"|"WED"|"THU"|"FRI"|"SAT"

gmtI字符串“GMT”或被忽略。

只有第一個參數(shù)是強制性的。第二,第三或兩者都可能被排除在外。

如果僅存在一個參數(shù),則該函數(shù)在參數(shù)代表的星期幾返回true值。如果將字符串“GMT”指定為第二個參數(shù),則時間取為GMT。否則,他們被認為是在當?shù)氐臅r區(qū)。

如果wd1wd1都已定義,則當前工作日在兩個有序工作日之間時,條件為真。界限是包容性的,但界限是有序的。如果指定了“GMT”參數(shù),則時間取為GMT。否則,使用本地時區(qū)。

日子的順序很重要 ; 在Firefox 49之前,總是會評估為真?,F(xiàn)在只會在當前日期為星期三或星期日的情況下評估為真。weekdayRange("SUN", "SAT")weekdayRange("WED", "SUN")

例子

function FindProxyForURL(url, host) {  return weekdayRange("MON", "FRI");}//returns true Monday through Friday (local timezone)
function FindProxyForURL(url, host) {  return weekdayRange("MON", "FRI", "GMT");}//returns true Monday through Friday (GMT timezone)
function FindProxyForURL(url, host) {  return weekdayRange("SAT");}//returns true true on Saturdays local time
function FindProxyForURL(url, host) {  return weekdayRange("SAT", "GMT");}//returns true on Saturdays GMT time
function FindProxyForURL(url, host) {  return weekdayRange("FRI", "MON");}//returns true Friday and Monday only (note, order does matter!)

dateRange()

句法

dateRange(<day1>, <month1>, <year1>, <day2>, <month2>, <year2>, <gmt>)

注意:(在Firefox 49之前)如果您希望函數(shù)將這些參數(shù)評估為范圍,則day1必須小于day2,month1必須小于month2,并且year1必須小于year2。看到下面的警告。

參數(shù)

day是1到31之間的月份的有序日期(作為整數(shù))。

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

月是下面的有序月份字符串之一。

"JAN"|"FEB"|"MAR"|"APR"|"MAY"|"JUN"|"JUL"|"AUG"|"SEP"|"OCT"|"NOV"|"DEC"

年是訂購的全年整數(shù)。例如,2016(不是 16).gmt是字符串“GMT”,它在GMT時區(qū)中進行時間比較,或者被忽略。如果沒有指定,時間將被視為在當?shù)貢r區(qū)。

如果只指定了一個值(來自每個類別:日,月,年),則該函數(shù)僅在符合該規(guī)范的日期才返回真值。如果同時指定了這兩個值,則結(jié)果在這些時間之間為真,包括邊界,但邊界是有序的。

日期,月份和年份的順序很重要 ; 在Firefox 49之前,會一直評估為。如果當前月份是12月或1月,現(xiàn)在只會評估為真。dateRange("JAN", "DEC")truedateRange("DEC", "JAN")

例子

function FindProxyForURL(url, host) {  return dateRange(1);}//returns true on the first day of each month, local timezone
function FindProxyForURL(url, host) {  return dateRange(1, "GMT")}//returns true on the first day of each month, GMT timezone
function FindProxyForURL(url, host) {  return dateRange(1, 15);}//returns true on the first half of each month
function FindProxyForURL(url, host) {  return dateRange(24, "DEC");}//returns true on 24th of December each year
function FindProxyForURL(url, host) {  return dateRange("JAN", "MAR");}//returns true on the first quarter of the year
function FindProxyForURL(url, host) {  return dateRange(1, "JUN", 15, "AUG");}//returns true from June 1st until August 15th, each year (including June 1st and August 15th)
function FindProxyForURL(url, host) {  return dateRange(1, "JUN", 1995, 15, "AUG", 1995);}//returns true from June 1st, 1995, until August 15th, same year
function FindProxyForURL(url, host) {  return dateRange("OCT", 1995, "MAR", 1996);}//returns true from October 1995 until March 1996 (including the entire month of October 1995 and March 1996)
function FindProxyForURL(url, host) {  return dateRange(1995);}//returns true during the entire year of 1995
function FindProxyForURL(url, host) {  return dateRange(1995, 1997);}//returns true from beginning of year 1995 until the end of year 1997

timeRange()

句法

timeRange(<hour1>, <min1>, <sec1>, <hour2>, <min2>, <sec2>, <gmt>)

注意:(在Firefox 49之前)如果希望函數(shù)將這些參數(shù)評估為范圍,則類別hour1,min1,sec1必須小于類別hour2,min2,sec2??吹较旅娴木妗?/p>

參數(shù)

hour是0到23之間的小時。(0是午夜,23是晚上11點。)minMinutes從0到59.secSeconds從0到59.gmt GMT或時區(qū)字符串“GMT”,或未指定,用于本地時區(qū)。

如果只指定了一個值(來自每個類別:小時,分鐘,秒),則該函數(shù)僅在符合該規(guī)范的時候返回真值。如果同時指定了這兩個值,則結(jié)果在這些時間之間為真,包括邊界,但邊界是有序的。

小時,分鐘,秒的順序 ; 在Firefox 49之前,總是會評估為真?,F(xiàn)在只會在當前時間為23:00或午夜時評估為真。timeRange(0, 23)timeRange(23, 0)

例子

function FindProxyForURL(url, host) {  return timerange(12);}//returns true from noon to 1pm
function FindProxyForURL(url, host) {  return timerange(12, 13);}//returns true from noon to 1pm
function FindProxyForURL(url, host) {  return timerange(12, "GMT");}//true from noon to 1pm, in GMT timezone
function FindProxyForURL(url, host) {  return timerange(9, 17);}//returns true from 9am to 5pm
function FindProxyForURL(url, host) {  return timerange(8, 30, 17, 00);}//returns true from 8:30am to 5:00pm
function FindProxyForURL(url, host) {  return timerange(0, 0, 0, 0, 0, 30);}//returns true between midnight and 30 seconds past midnight

例1

對本地主機以外的所有內(nèi)容使用代理

注意:由于以下所有示例都非常具體,因此尚未經(jīng)過測試。

所有未完全限定的主機或者本地域中的主機都將直接連接。其他一切都將通過w3proxy:8080。如果代理服務(wù)器關(guān)閉,連接將自動變?yōu)橹苯舆B接:

function FindProxyForURL(url, host) {  if (isPlainHostName(host) || dnsDomainIs(host, ".mozilla.org")) {    return "DIRECT";  } else {    return "PROXY w3proxy.mozilla.org:8080; DIRECT";  }}

注意:對于只有一個代理的情況,這是最簡單和最有效的autoconfig文件。

例2

如上所述,但是使用代理服務(wù)器在防火墻之外

如果存在屬于本地域但位于防火墻之外且只能通過代理服務(wù)器訪問的主機(如主Web服務(wù)器),則可以使用以下localHostOrDomainIs()函數(shù)處理這些異常:

function FindProxyForURL(url, host) {  if ((isPlainHostName(host) ||      dnsDomainIs(host, ".mozilla.org")) &&      !localHostOrDomainIs(host, "www.mozilla.org") &&      !localHostOrDoaminIs(host, "merchant.mozilla.org")) {        return "DIRECT";  } else {    return "PROXY w3proxy.mozilla.org:8080; DIRECT";  }}

上述示例將使用代理服務(wù)器,除mozilla.org域中的本地主機以外的所有其他服務(wù)器,但主機www.mozilla.org和merchant.mozilla.org將通過代理服務(wù)器的情況進一步例外。

請注意以上效率的例外順序:localHostOrDomainIs()函數(shù)僅針對本地域中的URL執(zhí)行,而不是針對每個URL執(zhí)行。注意在表達式之前的表達式的圓括號,以實現(xiàn)上述有效行為。

例3

僅在無法解析主機時才使用代理

此示例適用于內(nèi)部DNS服務(wù)器設(shè)置為只能解析內(nèi)部主機名的環(huán)境,目標是僅為不可解析的主機使用代理:

function FindProxyForURL(url, host) {  if (isResolvable(host))    return "DIRECT";  else    return "PROXY proxy.mydomain.com:8080";}

以上需要每次查詢DNS; 它可以與其他規(guī)則進行智能分組,以便僅在其他規(guī)則不產(chǎn)生結(jié)果時才咨詢DNS:

function FindProxyForURL(url, host) {  if (isPlainHostName(host) ||      dnsDomainIs(host, ".mydomain.com") ||      isResolvable(host)) {    return "DIRECT";  } else {    return "PROXY proxy.mydomain.com:8080";  }}

例4

基于子網(wǎng)的決定

在這個例子中,給定子網(wǎng)中的所有主機直接連接,其他連接通過代理連接:

function FindProxyForURL(url, host) {  if (isInNet(host, "198.95.0.0", "255.255.0.0"))    return "DIRECT";  else    return "PROXY proxy.mydomain.com:8080";}

同樣,通過在開始時添加冗余規(guī)則,可以最大限度地減少上述DNS服務(wù)器的使用:

function FindProxyForURL(url, host) {  if (isPlainHostName(host) ||      dnsDomainIs(host, ".mydomain.com") ||      isInNet(host, "198.95.0.0", "255.255.0.0")) {    return "DIRECT";  } else {    return "PROXY proxy.mydomain.com:8080";  }}

例5

基于URL模式的負載均衡/路由

這個例子更復(fù)雜。有四(4)個代理服務(wù)器; 其中一個對所有其他人來說都是一個熱門候補,所以如果其余三個中的任何一個倒下,第四個將會接管。此外,剩余的三臺代理服務(wù)器根據(jù)URL模式共享負載,這使得它們的緩存更加有效(三臺服務(wù)器上只有一個文檔副本 - 而不是每個副本上的副本)。負載分布如下:

Proxy

Purpose

#1

.com domain

#2

.edu domain

#3

all other domains

#4

hot stand-by

所有本地訪問都希望是直接的。所有代理服務(wù)器都在端口8080上運行(它們不需要)。請注意字符串如何與JavaScript中的+運算符連接。

function FindProxyForURL(url, host) {  if (isPlainHostName(host) || dnsDomainIs(host, ".mydomain.com"))      return "DIRECT";  else if (shExpMatch(host, "*.com"))      return "PROXY proxy1.mydomain.com:8080; " +             "PROXY proxy4.mydomain.com:8080";  else if (shExpMatch(host, "*.edu"))      return "PROXY proxy2.mydomain.com:8080; " +             "PROXY proxy4.mydomain.com:8080";  else      return "PROXY proxy3.mydomain.com:8080; " +             "PROXY proxy4.mydomain.com:8080";}

例6

為特定協(xié)議設(shè)置代理

大多數(shù)標準的JavaScript功能可用于FindProxyForURL()函數(shù)。例如,要根據(jù)協(xié)議設(shè)置不同的代理,可以使用substring()函數(shù):

function FindProxyForURL(url, host) {  
if (url.substring(0, 5) == "http:") {    
return "PROXY http-proxy.mydomain.com:8080";  
}  else if (url.substring(0, 4) == "ftp:") {   
 return "PROXY ftp-proxy.mydomain.com:8080";  
 }  else if (url.substring(0, 7) == "gopher:") {    
 return "PROXY gopher-proxy.mydomain.com:8080"; 
  }  else if (url.substring(0, 6) == "https:" || url.substring(0, 6) == "snews:") { 
  return "PROXY security-proxy.mydomain.com:8080";  } else {   
   return "DIRECT";  
   }
 }

注意:使用前面介紹的shExpMatch()函數(shù)可以完成相同的操作。

例如:

// ...if (shExpMatch(url, "http:*")) {  return "PROXY http-proxy.mydomain.com:8080;}// ...

自動配置文件可以由CGI腳本輸出。例如,當根據(jù)客戶端IP地址(CGI中的REMOTE_ADDR環(huán)境變量)使自動配置文件的行為不同時,這很有用。

使用isInNet(),isResolvable()dnsResolve()功能應(yīng)該仔細考慮,因為它們需要被咨詢的DNS服務(wù)器。所有其他與自動配置相關(guān)的功能都是單純的字符串匹配功能,不需要使用DNS服務(wù)器。如果使用代理服務(wù)器,代理服務(wù)器將執(zhí)行其DNS查找,這將使DNS服務(wù)器的影響加倍。大多數(shù)情況下,這些功能對于達到預(yù)期效果并不是必需的。

在MDN上編輯此頁(https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy servers_and_tunneling / Proxy_Auto-Configuration(PAC%29_file $ edit)

上一篇: 下一篇: