예제 #1
0
 public RetriableStreamImpl(Response initialResponse, Func <long, Task <Response> > responseFactory, ResponseClassifier responseClassifier, int maxRetries)
 {
     _currentStream      = initialResponse.ContentStream;
     _responseClassifier = responseClassifier;
     _responseFactory    = responseFactory;
     _maxRetries         = maxRetries;
     Length = _currentStream.Length;
 }
예제 #2
0
 public static async Task <Stream> CreateAsync(
     Func <long, Response> responseFactory,
     Func <long, Task <Response> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(Create(await asyncResponseFactory(0).ConfigureAwait(false), responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
예제 #3
0
 public static Stream Create(
     Func <long, Response> responseFactory,
     Func <long, Task <Response> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(Create(responseFactory(0), responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
예제 #4
0
 public RetriableStreamImpl(Response initialResponse, Func <long, Response> responseFactory, Func <long, Task <Response> > asyncResponseFactory, ResponseClassifier responseClassifier, int maxRetries)
 {
     _initialStream        = initialResponse.ContentStream;
     _currentStream        = initialResponse.ContentStream;
     _responseFactory      = responseFactory;
     _responseClassifier   = responseClassifier;
     _asyncResponseFactory = asyncResponseFactory;
     _maxRetries           = maxRetries;
 }
예제 #5
0
 public static Stream Create(
     Response initialResponse,
     Func <long, Response> responseFactory,
     Func <long, Task <Response> > asyncResponseFactory,
     ResponseClassifier responseClassifier,
     int maxRetries)
 {
     return(new RetriableStreamImpl(initialResponse, responseFactory, asyncResponseFactory, responseClassifier, maxRetries));
 }
예제 #6
0
        public static async Task <RequestFailedException> CreateRequestFailedExceptionAsync(string message, Response response, bool async)
        {
            StringBuilder messageBuilder = new StringBuilder()
                                           .AppendLine(message)
                                           .Append("Status: ")
                                           .Append(response.Status.ToString())
                                           .Append(" (")
                                           .Append(response.ReasonPhrase)
                                           .AppendLine(")");

            if (response.ContentStream != null &&
                ResponseClassifier.IsTextResponse(response, out var encoding))
            {
                messageBuilder
                .AppendLine()
                .AppendLine("Content:");

                using (var streamReader = new StreamReader(response.ContentStream, encoding))
                {
                    string content = async ? await streamReader.ReadToEndAsync() : streamReader.ReadToEnd();

                    messageBuilder.AppendLine(content);
                }
            }


            messageBuilder
            .AppendLine()
            .AppendLine("Headers:");
            foreach (var responseHeader in response.Headers)
            {
                messageBuilder.AppendLine($"{responseHeader.Name}: {responseHeader.Value}");
            }

            return(new RequestFailedException(response.Status, messageBuilder.ToString()));
        }
예제 #7
0
 public static async Task <Stream> Create(Func <long, Task <Response> > responseFactory, ResponseClassifier responseClassifier, int maxRetries)
 {
     return(new RetriableStreamImpl(await responseFactory(0), responseFactory, responseClassifier, maxRetries));
 }
예제 #8
0
 /// <summary>
 /// Creates a new instance of <see cref="HttpMessage"/>.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="responseClassifier">The response classifier.</param>
 public HttpMessage(Request request, ResponseClassifier responseClassifier)
 {
     Request            = request;
     ResponseClassifier = responseClassifier;
     BufferResponse     = true;
 }