diff --git a/netwerk/base/src/nsProtocolProxyService.cpp b/netwerk/base/src/nsProtocolProxyService.cpp index b7c437fb537..92692cbba41 100644 --- a/netwerk/base/src/nsProtocolProxyService.cpp +++ b/netwerk/base/src/nsProtocolProxyService.cpp @@ -306,7 +306,8 @@ NS_IMPL_CI_INTERFACE_GETTER2(nsProtocolProxyService, nsIProtocolProxyService2) nsProtocolProxyService::nsProtocolProxyService() - : mFilters(nsnull) + : mFilterLocalHosts(PR_FALSE) + , mFilters(nsnull) , mProxyConfig(PROXYCONFIG_DIRECT) , mHTTPProxyPort(-1) , mFTPProxyPort(-1) @@ -543,6 +544,12 @@ nsProtocolProxyService::CanUseProxy(nsIURI *aURI, PRInt32 defaultPort) } } + // Don't use proxy for local hosts (plain hostname, no dots) + if (!is_ipaddr && mFilterLocalHosts && (kNotFound == host.FindChar('.'))) { + LOG(("Not using proxy for this local host [%s]!\n", host.get())); + return PR_FALSE; // don't allow proxying + } + PRInt32 index = -1; while (++index < PRInt32(mHostFiltersArray.Length())) { HostInfo *hinfo = mHostFiltersArray[index]; @@ -849,8 +856,10 @@ nsProtocolProxyService::Resolve(nsIURI *uri, PRUint32 flags, PRBool usePAC; rv = Resolve_Internal(uri, info, flags, &usePAC, result); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) { + LOG(("Resolve_Internal returned rv(0x%08x)\n", rv)); return rv; + } if (usePAC && mPACMan) { NS_ASSERTION(*result == nsnull, "we should not have a result yet"); @@ -1069,6 +1078,8 @@ nsProtocolProxyService::LoadHostFilters(const char *filters) // filter = ( host | domain | ipaddr ["/" mask] ) [":" port] // filters = filter *( "," LWS filter) // + // Reset mFilterLocalHosts - will be set to true if "" is in pref string + mFilterLocalHosts = PR_FALSE; while (*filters) { // skip over spaces and , while (*filters && (*filters == ',' || IS_ASCII_SPACE(*filters))) @@ -1091,11 +1102,6 @@ nsProtocolProxyService::LoadHostFilters(const char *filters) filters = endhost; // advance iterator up front - HostInfo *hinfo = new HostInfo(); - if (!hinfo) - return; // fail silently - hinfo->port = portLocation ? atoi(portLocation + 1) : 0; - // locate end of host const char *end = maskLocation ? maskLocation : portLocation ? portLocation : @@ -1103,6 +1109,20 @@ nsProtocolProxyService::LoadHostFilters(const char *filters) nsCAutoString str(starthost, end - starthost); + // If the current host filter is "", then all local (i.e. + // no dots in the hostname) hosts should bypass the proxy + if (str.EqualsIgnoreCase("")) { + mFilterLocalHosts = PR_TRUE; + LOG(("loaded filter for local hosts " + "(plain host names, no dots)\n")); + // Continue to next host filter; + continue; + } + + // For all other host filters, create HostInfo object and add to list + HostInfo *hinfo = new HostInfo(); + hinfo->port = portLocation ? atoi(portLocation + 1) : 0; + PRNetAddr addr; if (PR_StringToNetAddr(str.get(), &addr) == PR_SUCCESS) { hinfo->is_ipaddr = PR_TRUE; diff --git a/netwerk/base/src/nsProtocolProxyService.h b/netwerk/base/src/nsProtocolProxyService.h index c696e96e904..fd3c2facdf0 100644 --- a/netwerk/base/src/nsProtocolProxyService.h +++ b/netwerk/base/src/nsProtocolProxyService.h @@ -353,6 +353,9 @@ protected: ~FilterLink() { if (next) delete next; } }; + // Indicates if local hosts (plain hostnames, no dots) should use the proxy + PRBool mFilterLocalHosts; + // Holds an array of HostInfo objects nsTArray > mHostFiltersArray; diff --git a/netwerk/test/unit/test_protocolproxyservice.js b/netwerk/test/unit/test_protocolproxyservice.js index 44cfcdae33e..253336cd95d 100644 --- a/netwerk/test/unit/test_protocolproxyservice.js +++ b/netwerk/test/unit/test_protocolproxyservice.js @@ -384,6 +384,79 @@ function run_pac_cancel_test() { do_test_pending(); } +function check_host_filters(hostList, bShouldBeFiltered) { + var uri; + var proxy; + for (var i=0; i"); + do_check_eq(prefs.getCharPref("network.proxy.no_proxies_on"), + hostFilterList + ", "); + + // Amend lists - move local domain to filtered list + uriStrFilterList.push(uriStrUseProxyList.pop()); + check_host_filters(uriStrFilterList, true); + check_host_filters(uriStrUseProxyList, false); + + // Cleanup + prefs.setCharPref("network.proxy.no_proxies_on", ""); + do_check_eq(prefs.getCharPref("network.proxy.no_proxies_on"), ""); + + do_test_finished(); +} + function run_test() { register_test_protocol_handler(); run_filter_test(); @@ -399,4 +472,5 @@ function run_test_continued() { } function run_test_continued_2() { + run_proxy_host_filters_test(); }