Beispiel #1
0
    private async Task <ResponseResult> ExecuteTaskCoreAsync(
        IEnumerable <ApiResponseErrorHandlingDelegate> errorHandlers,
        HttpRequestMessageBuilder requestMessageBuilder,
        CancellationToken cancellationToken = default,
        bool isSts = false)
    {
        var startTime = DateTime.Now;

        // Logs full url when HTTPtracing is enabled.
        if (trace)
        {
            var fullUrl = requestMessageBuilder.RequestUri;
        }

        var v4Authenticator = new V4Authenticator(Secure,
                                                  AccessKey, SecretKey, Region,
                                                  SessionToken);

        requestMessageBuilder.AddOrUpdateHeaderParameter("Authorization",
                                                         v4Authenticator.Authenticate(requestMessageBuilder, isSts));

        var request = requestMessageBuilder.Request;

        ResponseResult responseResult;

        try
        {
            var response = await HTTPClient.SendAsync(request,
                                                      HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                           .ConfigureAwait(false);

            responseResult = new ResponseResult(request, response);
            if (requestMessageBuilder.ResponseWriter != null)
            {
                requestMessageBuilder.ResponseWriter(responseResult.ContentStream);
            }
        }
        catch (OperationCanceledException)
        {
            throw;
        }
        catch (Exception e)
        {
            responseResult = new ResponseResult(request, e);
        }

        HandleIfErrorResponse(responseResult, errorHandlers, startTime);
        return(responseResult);
    }