public override bool GetProxies(Uri destination, out IList <string> proxyList) { try { proxyList = null; EnsureEngineAvailable(); // after EnsureEngineAvailable we expect State to be CompilationSuccess, otherwise return. if (State != AutoWebProxyState.Completed) { // the script can't run, say we're not ready and bypass return(false); } bool result = false; try { string proxyListString = scriptInstance.FindProxyForURL(destination.ToString(), destination.Host); GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::GetProxies() calling ExecuteFindProxyForURL() for destination:" + ValidationHelper.ToString(destination) + " returned scriptReturn:" + ValidationHelper.ToString(proxyList)); proxyList = ParseScriptResult(proxyListString); result = true; } catch (Exception exception) { if (Logging.On) { Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_script_execution_error, exception)); } } return(result); } finally { // Reset state of 'aborted', since next call to GetProxies() must not use previous aborted state. aborted = false; } }
internal StringCollection GetProxies(Uri destination, bool returnFirstOnly, out AutoWebProxyState autoWebProxyState, ref int syncStatus) { GlobalLog.Print("AutoWebProxyScriptEngine#" + ValidationHelper.HashString(this) + "::GetProxies() state:" + ValidationHelper.ToString(state)); if (state == AutoWebProxyState.DiscoveryFailure) { // No engine will be available anyway, shortcut the call. autoWebProxyState = state; return(null); } // This whole thing has to be locked, both to prevent simultaneous downloading / compilation, and // because the script isn't threadsafe. string scriptReturn = null; try { EnterLock(ref syncStatus); if (syncStatus != SyncStatus.LockOwner) { // This is typically because a download got aborted. autoWebProxyState = AutoWebProxyState.DownloadFailure; return(null); } autoWebProxyState = EnsureEngineAvailable(ref syncStatus); if (autoWebProxyState != AutoWebProxyState.CompilationSuccess) { // the script can't run, say we're not ready and bypass return(null); } autoWebProxyState = AutoWebProxyState.ExecutionFailure; try { scriptReturn = scriptInstance.FindProxyForURL(destination.ToString(), destination.Host); autoWebProxyState = AutoWebProxyState.ExecutionSuccess; GlobalLog.Print("AutoWebProxyScriptEngine#" + ValidationHelper.HashString(this) + "::GetProxies() calling ExecuteFindProxyForURL() for destination:" + ValidationHelper.ToString(destination) + " returned scriptReturn:" + ValidationHelper.ToString(scriptReturn)); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } if (Logging.On) { Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_script_execution_error, exception)); } GlobalLog.Print("AutoWebProxyScriptEngine#" + ValidationHelper.HashString(this) + "::GetProxies() calling ExecuteFindProxyForURL() for destination:" + ValidationHelper.ToString(destination) + " threw:" + ValidationHelper.ToString(exception)); } } finally { ExitLock(ref syncStatus); } if (autoWebProxyState == AutoWebProxyState.ExecutionFailure) { // the script failed at runtime, say we're not ready and bypass return(null); } StringCollection proxies = ParseScriptReturn(scriptReturn, destination, returnFirstOnly); GlobalLog.Print("AutoWebProxyScriptEngine#" + ValidationHelper.HashString(this) + "::GetProxies() proxies:" + ValidationHelper.ToString(proxies)); return(proxies); }