public static async ValueTask <HttpRes> SendAsync(this IHttpService http, HttpReq req, int retryTimes = 1, int delaySeconds = 0) { return(await ActionHelper.TryAsync(async() => await http.ExecuteAsync(req).DonotCapture(), retryTimes, delaySeconds, HttpRes.CreateError) .DonotCapture()); }
public async Task <IWatcherCheckResult> ExecuteAsync() { var baseUrl = _configuration.Uri.ToString(); var fullUrl = _configuration.Request.GetFullUrl(baseUrl); try { var response = await _httpService.ExecuteAsync(baseUrl, _configuration.Request, _configuration.Timeout); var isValid = HasValidResponse(response); if (!isValid) { return(WebWatcherCheckResult.Create(this, false, _configuration.Uri, _configuration.Request, response, $"Web endpoint: '{fullUrl}' has returned an invalid response with status code: {response.StatusCode}.")); } return(await EnsureAsync(fullUrl, response)); } catch (TaskCanceledException exception) { return(WebWatcherCheckResult.Create(this, false, _configuration.Uri, _configuration.Request, null, $"A connection timeout occurred while trying to access the Web endpoint: '{fullUrl}'.")); } catch (Exception exception) { throw new WatcherException($"There was an error while trying to access the Web endpoint: '{fullUrl}'.", exception); } }
private async Task <HttpResponse <T> > GetDeserializedObject <T>(string requestUrl, HttpMode mode, string message = null) { var result = await _httpService.ExecuteAsync(requestUrl, mode, message); var response = new HttpResponse <T> { HttpStatusCode = result.HttpStatusCode, Message = result.Message, Location = result.Location }; if (result.IsSuccessStatusCode) { response.Result = await Task.Run(() => { return(JsonConvert.DeserializeObject <T>(result.Result)); }); } return(response); }
public static async ValueTask RawTest(IHttpService service, IList <HttpReq> reqs, int rounds) { var before = GC.GetTotalMemory(true); var t = await SimpleWatch.DoAsync(async() => { for (var i = 0; i < rounds; i++) { foreach (var req in reqs) { var res = await service.ExecuteAsync(req).DonotCapture(); res.ThrowIfError(); } } }).DonotCapture(); var after = GC.GetTotalMemory(true); Console.WriteLine($"[{service.GetType().SimpleName()}]: " + $"Round: {rounds}, " + $"Time: {t.TotalSeconds:f2}s, " + $"Memory: {after - before}byte"); }
public async ValueTask LightHttpService_Test(string url) { await _lightHttpService.ExecuteAsync(HttpReq.Get(url)).DonotCapture(); }
public async ValueTask HttpClientExtService_Test(string url) { await _httpClientExtService.ExecuteAsync(HttpReq.Get(url)).DonotCapture(); }