public DispatchInfo Send(HttpRequest request, Action <HttpResponse> onResponse) { DispatchInfo info = new DispatchInfo(request, onResponse); SendInternal(info); return(info); }
internal HttpResponse Send(DispatchInfo info) { HttpRequest request = info.request; HttpResponse response = null; DateTime then = DateTime.Now; while (true) { requestHandler.Prepare(request); LogRequest(request); response = IsCacheAvailable(request) ? GetResponseFromCache(request, info.DownloadProgress, info.cancellationToken) : GetResponseFromSocket(request, info.DownloadProgress, info.cancellationToken); response.Duration = DateTime.Now - then; LogResponse(response); if (IsRedirect(response)) { request = MakeRedirectRequest(response); } else { break; } } return(response); }
void TransmitIfPossible() { if (pendingRequests.Count > 0) { if (ongoingRequests.Count < settings.maxConcurrentRequests) { DispatchInfo info = pendingRequests.Dequeue(); if (!info.IsDisposed) { ongoingRequests.Add(info); TransmitInWorkerThread(info); } } } }
void TransmitInWorkerThread(DispatchInfo info) { ThreadPool.QueueUserWorkItem(state => { try { HttpResponse response = messenger.Send(info); ExecuteOnMainThread(() => { ongoingRequests.Remove(info); info.InvokeCallback(response); TransmitIfPossible(); }); } catch (Exception exception) { ExecuteOnMainThread(() => { throw exception; }); } }); }
internal CancellationToken(DispatchInfo source) { this.source = source; }
internal WaitForResponse(HttpRequest request) { this.dispatchInfo = new DispatchInfo(request, SetResponse); }
void SendInternal(DispatchInfo info) { pendingRequests.Enqueue(info); TransmitIfPossible(); }