private async Task <HttpResponseMessage> InternalExecuteAsync(HttpRequestMessage message, Uri proxyUri, CancellationToken token) { var targetUri = message.RequestUri; //TODO 过滤不支持的http版本 var request = await message.ToFullHttpRequestAsync(false).ConfigureAwait(false); IFullHttpResponse response = null; HttpResponseMessage outterResponse; try { response = await RequestExecutor.InternalExecuteAsync(request, targetUri, proxyUri, token).ConfigureAwait(false); outterResponse = response.ToHttpResponseMessage(); } finally { response.SafeRelease(); } outterResponse.Version = message.Version; outterResponse.RequestMessage = message; return(outterResponse); }
protected async Task DoRequestAsync(List <Uri> uris, int requestCount) { foreach (var uri in uris) { var sw = Stopwatch.StartNew(); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); var tasks = Enumerable.Range(0, requestCount).Select(async m => { IFullHttpResponse response = null; try { var request = new DefaultFullHttpRequest(DNHttpVersion.Http11, DNHttpMethod.Get, uri.OriginalString); response = await _executor.ExecuteAsync(request, cts.Token).ConfigureAwait(false); Assert.AreEqual(200, response.Status.Code); } catch { } finally { response.SafeRelease(); } }).ToArray(); await Task.WhenAll(tasks).ConfigureAwait(false); sw.Stop(); Debug.WriteLine($"{uri.OriginalString}:{sw.Elapsed}"); } }