Ejemplo n.º 1
0
 private Task <HttpResponseMessage> SendRequestAsync(HttpClient client,
                                                     HttpRequestDto request,
                                                     HttpContent content,
                                                     CancellationToken cancellationToken)
 {
     return(httpRequestSender.SendAsync(client, BuildMessage(request, content), cancellationToken));
 }
Ejemplo n.º 2
0
 public Task <IHttpResponse <TResponse> > SendAsync <TResponse>(HttpClient client,
                                                                HttpRequestDto request,
                                                                Func <HttpResponseMessage, CancellationToken, Task> onError,
                                                                CancellationToken cancellationToken)
 {
     return(SendAsync <None, TResponse>(client, ToNoneTypedRequest(request), onError, cancellationToken));
 }
Ejemplo n.º 3
0
 public async Task <IHttpResponse> SendAsync <TRequest>(HttpClient client,
                                                        HttpRequestDto <TRequest> request,
                                                        Func <HttpResponseMessage, CancellationToken, Task> onError,
                                                        CancellationToken cancellationToken)
 {
     return(await SendAsync <TRequest, None>(client, request, onError, cancellationToken));
 }
Ejemplo n.º 4
0
        private HttpRequestMessage BuildMessage(HttpRequestDto request, HttpContent content)
        {
            var msg = new HttpRequestMessage(request.Method, request.Uri);

            if (request.Headers != null)
            {
                foreach (var header in request.Headers)
                {
                    msg.Headers.Add(header.Key, header.Value);
                }
            }

            if (request.Timeout.HasValue && request.Timeout != TimeSpan.Zero)
            {
                msg.Properties.Add(Constants.PropertyTimeoutInMs, request.Timeout);
            }
            if (request.RetryCount.HasValue && request.RetryCount > 0)
            {
                msg.Properties.Add(Constants.PropertyRetryCount, request.RetryCount);
            }

            if (content != null)
            {
                msg.Content = content;
            }

            return(msg);
        }
Ejemplo n.º 5
0
 private HttpRequestDto <None> ToNoneTypedRequest(HttpRequestDto request)
 {
     return(new HttpRequestDto <None>
     {
         Content = null,
         ContentType = null,
         Headers = request.Headers,
         Method = request.Method,
         RetryCount = request.RetryCount,
         Timeout = request.Timeout,
         Uri = request.Uri
     });
 }
Ejemplo n.º 6
0
        public async Task <IHttpResponse <TResponse> > SendAsync <TRequest, TResponse>(HttpClient client,
                                                                                       HttpRequestDto <TRequest> request,
                                                                                       Func <HttpResponseMessage, CancellationToken, Task> onError,
                                                                                       CancellationToken cancellationToken)
        {
            using var streamContent = await BuildContent(request.Content, request.ContentType, cancellationToken);

            using var rsp = await this.SendRequestAsync(client, request, streamContent, cancellationToken);

            return(await BuildResponseDto <TResponse>(rsp, onError, cancellationToken));
        }