public DefaultHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection) { client = new WebClientWithTimeout(); client.BaseAddress = baseUri.AbsoluteUri; client.Timeout = (int)timeout.TotalMilliseconds; client.ReadWriteTimeout = client.Timeout; if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { client.Credentials = new NetworkCredential(username, password); } #if ! MONO ServicePointManager.FindServicePoint(baseUri).SetTcpKeepAlive(true, 300, 30); #endif //The first time a request is made to a URI, the ServicePointManager //will create a ServicePoint to manage connections to a particular host //This process is expensive and slows down the first created view. //The call to BeginRequest is basically an async, no-op HTTP request to //initialize the ServicePoint before the first view request is made. if (shouldInitConnection) client.DownloadStringAsync(baseUri); }
private void Worker(object state) { if (log.IsDebugEnabled) log.Debug("Started working."); while (!this.stopEvent.WaitOne(0)) { if (this.requestFactory == null) this.requestFactory = this.CreateRequestFactory(); // false means that the url was not responding or failed while reading this.statusPool = this.urls.ToDictionary(u => u, u => true); this.urlIndex = 0; // this will quit when all nodes go down or we're stopped externally this.ProcessPool(); // pool fail if (!this.stopEvent.WaitOne(0)) { if (log.IsWarnEnabled) log.Warn("All nodes are dead, sleeping for a while."); this.Trigger(null); this.SleepUntil(this.DeadTimeout); // recreate the client after failure this.AbortRequests(); if (this.requestFactory != null) { this.requestFactory.Dispose(); this.requestFactory = null; } } } }
protected void Dispose() { AppDomain.CurrentDomain.DomainUnload -= CurrentDomain_DomainUnload; this.AbortRequests(); if (this.requestFactory != null) { using (this.requestFactory) this.requestFactory.CancelAsync(); this.requestFactory = null; } }
private static Uri ResolveBucketUri(WebClientWithTimeout client, Uri root, string bucketName) { try { var bucket = ConfigHelper.ResolveBucket(client, root, bucketName); if (bucket == null) return null; if (String.IsNullOrEmpty(bucket.streamingUri)) { log.ErrorFormat("Url {0} for bucket {1} returned a config with no streamingUri", root, bucketName); return null; } return new Uri(root, bucket.streamingUri); } catch (Exception e) { log.Error("Error resolving streaming uri: " + root, e); return null; } }
internal static HttpWebRequestWrapper Create(WebClientWithTimeout client, string path) { return new HttpWebRequestWrapper { client = client, path = path }; }
public DefaultHttpRequestWrapper(WebClientWithTimeout client, string path) { this.method = HttpMethod.Get; httpWebRequestWrapper = HttpWebRequestWrapper.Create(client, path); }
internal static HttpWebRequestWrapper Create(WebClientWithTimeout client, string path) { return(new HttpWebRequestWrapper { client = client, path = path }); }