Sun Java System Web Proxy Server 4.0.3 2006Q2 Administration Guide

Example 7: Proxying a Specific Protocol

You can set a proxy to be for a specific protocol. Most of the standard JavaScript functionality is available for use in the FindProxyForURL() function. For example, to set different proxies based on the protocol, you can use the substring() function:

    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";
        }
    }

You can also accomplish this using the shExpMatch() function; for example:

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