Can't get full url when setting local PAC file

2.3k Views Asked by At

I'm writing a .pac file for browser. I want browser to check url that i enter matches the rules.

function FindProxyForURL(url, host) {
    url=url.toLowerCase();
    host=host.toLowerCase();
    debugPAC ="PAC Debug Information\n";
    debugPAC +="-----------------------------------\n";
    debugPAC +="Machine IP: " + myIpAddress() + "\n";
    debugPAC +="Hostname: " + host + "\n";
    if (isResolvable(host)) {resolvableHost = "True"} else {resolvableHost = "False"};
    debugPAC +="Host Resolvable: " + resolvableHost + "\n";
    debugPAC +="Hostname IP: " + dnsResolve(host) + "\n";
    if (isPlainHostName(host)) {plainHost = "True"} else {plainHost = "False"};
    debugPAC +="Plain Hostname: " + plainHost + "\n";
    debugPAC +="Domain Levels: " + dnsDomainLevels(host) + "\n";
    debugPAC +="URL: " + url + "\n";
    if (url.substring(0,5)=="http:") {protocol="HTTP";}
    else if (url.substring(0,6)=="https:") {protocol="HTTPS";} 
    else if (url.substring(0,4)=="ftp:") {protocol="FTP";}
    else {protocol="Unknown";}
    debugPAC +="Protocol: " + protocol + "\n";
    if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);}
    if(shExpMatch(url,"*://login.dangdang.com/images/bg/dataimg/dly_0807_01*"))
    {
        var noproxy=url;
        alert("noproxy4simplejpg"+noproxy);
        return "PROXY 192.168.0.101:808";
    }
    if(shExpMatch(url,"*://login.dangdang.com/script/sign_in2011.js"))
    {
        var noproxy=url;
        alert("noproxy4js"+noproxy);
        return "DIRECT";
    }
    if(shExpMatch(url,"*login.dangdang.com/*.gif*"))
    {
        var noproxy=url;
        alert("noproxy4gif"+noproxy);
        return "DIRECT";
    }
    if(shExpMatch(url,"*login.dangdang.com/*"))
    {
        var proxy=url;
        alert("proxy4login"+proxy);
        return "PROXY 192.168.0.101:808";
    }
    else
        return  "DIRECT"; 
}

The question is that i want to receive the complete url from browser rather than protocol and host . But now i can only receive url such as https://www.login.dngdang.com/ by testing, but i entered https://www.login.dangdang.com/xxx. what's wrong?

1

There are 1 best solutions below

1
On

I see your URL uses HTTPS - https://www.login.dangdang.com/xxx

The path and query components of https:// URLs are stripped for security reasons by browsers by default.

In Chrome, you can disable this by setting PacHttpsUrlStrippingEnabled to false

In Firefox the preference is network.proxy.autoconfig_url.include_path.

Browsers strip privacy and security sensitive parts of https:// URLs before passing them on to PAC scripts (Proxy Auto Config) during proxy resolution.

When True, the security feature is enabled, and https:// URLs are stripped before submitting them to a PAC script. In this manner the PAC script is not able to view data that is ordinarily protected by an encrypted channel (such as the URL's path and query).

When False, the security feature is disabled, and PAC scripts are implicitly granted the ability to view all components of an https:// URL. This applies to all PAC scripts regardless of origin (including those fetched over an insecure transport, or discovered insecurely through WPAD).

This defaults to True (security feature enabled).

It is recommended that this be set to True. The only reason to set it to False is if it causes a compatibility problem with existing PAC scripts.