コード例 #1
0
        public void GetTimeout_should_return_default_timeout_for_long_operations()
        {
            var longOperationTimeout = 30.Seconds();
            var requestTimeouts      = new RequestTimeouts(10.Seconds(), 20.Seconds(), longOperationTimeout);

            var timeout = TimeoutSpecification.LongOperationTimeout.GetTimeout(CreateWriteRequest(), requestTimeouts);

            timeout.Should().Be(longOperationTimeout);
        }
コード例 #2
0
            static async Task <FailoverDecision> AuthorizationErrorsFailover(RequestTimeouts timeouts, IAuthenticator authProvider, IHttpResponse response, uint attempt)
            {
                switch (attempt)
                {
                case 0 when response.Status.IsUnauthorized:
                    await authProvider.AuthenticateAsync(true, timeouts.DefaultReadTimeout).ConfigureAwait(false);

                    return(FailoverDecision.RepeatRequest);

                default:
                    return(FailoverDecision.LetItFail);
                }
            }
コード例 #3
0
        public static OpenIdClient Create(RequestTimeouts requestTimeouts, IHttpClientConfiguration clientConfiguration, ILog log)
        {
            var http = new HttpRequestFactory(
                clientConfiguration,
                requestTimeouts,
                null,
                HandleOpenIdErrorResponse,
                null,
                Serializer,
                log
                );

            return(new OpenIdClient(http));
        }
コード例 #4
0
 public HttpRequest(
     Request request,
     RequestTimeouts requestTimeouts,
     Func <Request, TimeSpan, Task <Request> >?requestTransformAsync,
     Func <IHttpResponse, ValueTask <bool> >?errorResponseHandler,
     FailoverAsync?failoverAsync,
     IClusterClient clusterClient,
     IJsonSerializer serializer)
 {
     this.request               = request ?? throw new ArgumentNullException(nameof(request));
     this.requestTimeouts       = requestTimeouts ?? throw new ArgumentNullException(nameof(requestTimeouts));
     this.requestTransformAsync = requestTransformAsync;
     this.errorResponseHandler  = errorResponseHandler;
     this.failoverAsync         = failoverAsync;
     this.clusterClient         = clusterClient ?? throw new ArgumentNullException(nameof(clusterClient));
     this.serializer            = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
コード例 #5
0
        public HttpRequestFactory(
            IHttpClientConfiguration configuration,
            RequestTimeouts requestTimeouts,
            Func <Request, TimeSpan, Task <Request> >?requestTransformAsync,
            Func <IHttpResponse, ValueTask <bool> >?errorResponseHandler,
            FailoverAsync?failover,
            IJsonSerializer serializer,
            ILog log)
        {
            this.requestTimeouts       = requestTimeouts ?? throw new ArgumentNullException(nameof(requestTimeouts));
            this.requestTransformAsync = requestTransformAsync;
            this.errorResponseHandler  = errorResponseHandler;
            this.failover   = failover;
            this.serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));

            clusterClient = ClusterClientFactory.CreateClusterClient(configuration, log);
        }
コード例 #6
0
        private HttpRequestFactory CreateHttp(
            IHttpClientConfiguration clientConfiguration,
            RequestTimeouts requestTimeouts,
            IAuthenticator authenticator,
            IJsonSerializer jsonSerializer,
            ILog log)
        {
            FailoverAsync?unauthorizedFailover =
                EnableUnauthorizedFailover
                    ? (response, attempt) => AuthorizationErrorsFailover(requestTimeouts, authenticator, response, attempt)
                    : null;

            return(new HttpRequestFactory(
                       clientConfiguration,
                       requestTimeouts,
                       (request, span) => AuthenticateRequestAsync(authenticator, request, span),
                       HandleApiErrors,
                       unauthorizedFailover,
                       jsonSerializer,
                       log
                       ));