private async Task <HttpResponseMessage> ResultFromRequestAsync(IHttpBuilderContext context, HttpRequestMessage request, CancellationToken token) { ExceptionDispatchInfo capturedException = null; HttpResponseMessage response = null; try { var sendingContext = new HttpSendingContext(context, request); token.ThrowIfCancellationRequested(); await context.HandlerRegister.OnSending(sendingContext); if (sendingContext.Result != null) { response = sendingContext.Result; } else { token.ThrowIfCancellationRequested(); using (var client = _clientBuilder.Build()) response = await client.SendAsync(request, context.CompletionOption, token); } if (!context.IsSuccessfulResponse(response) && context.ExceptionFactory != null) { var ex = context.ExceptionFactory(response, request); if (ex != null) { throw ex; } } var sentContext = new HttpSentContext(context, request, response); token.ThrowIfCancellationRequested(); await context.HandlerRegister.OnSent(sentContext); response = sentContext.Result; } catch (Exception ex) { capturedException = ExceptionDispatchInfo.Capture(ex); } if (capturedException != null) { var exContext = new HttpExceptionContext(context, response, capturedException.SourceException); await context.HandlerRegister.OnException(exContext); if (!exContext.ExceptionHandled) { capturedException.Throw(); } } return(response); }
private static void InitializeOriginalWebsiteService() { OriginalHttpClientBuilder = new HttpClientBuilder(() => ServiceTestsConstants.PaymentSystemAuthenticationConfiguration); OriginalHttpClient = OriginalHttpClientBuilder.Build(); OriginalWebsiteManagementService = new Sdk.Services.WebsiteManagementService(OriginalHttpClient, BaseAddress); }
public SmartCacheClient(IHttpClientBuilder httpClientBuilder) { this.httpClientBuilder = httpClientBuilder; httpClient = httpClientBuilder.Build(); }