Describe the bug
I want to stream response data to my API for advanced processing. For this purpose I use AdvancedResponseWriter because I also want to handle errors from remote resource (=> I cannot use RestSharp.RestClient.DownloadStreamAsync), but the latest changes close response stream too early. It is cause by using in:
using var internalResponse = await ExecuteRequestAsync(request, cancellationToken).ConfigureAwait(false);
To Reproduce
[Test]publicasyncTaskAdvancedResponseWriterKeepStream(){awaitforeach(varlineinMyAsyncApi()){Console.WriteLine(line);}}privateasyncIAsyncEnumerable<string>MyAsyncApi(){usingvarclient=newRestClient(newRestClientOptions("https://demo.ckan.org/"));varrestRequest=newRestRequest("dataset/c322307a-b871-44fe-a602-32ee8437ff04/resource/b53c9e72-6b59-4cda-8c0c-7d6a51dad12a/download/sample.csv");Streamstream=null;restRequest.AdvancedResponseWriter=(response,request)=>{if(!response.IsSuccessStatusCode){thrownewException($"Do something with unsuccessful response: {response}");}stream=response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();returnnewRestResponse(request);};awaitclient.ExecuteAsync(restRequest);usingvarreader=newStreamReader(stream,Encoding.UTF8);while(reader.Peek()>=0){// advanced processingyieldreturnawaitreader.ReadLineAsync();}}Expected behavior
Be able to stream response to API.
Stack trace
System.ArgumentException : Stream was not readable.
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding)
Desktop (please complete the following information):
- OS:
macOS - .NET version:
NET 5 - Version:
110.2.0
Describe the bug
I want to stream response data to my API for advanced processing. For this purpose I use
AdvancedResponseWriterbecause I also want to handle errors from remote resource (=> I cannot useRestSharp.RestClient.DownloadStreamAsync), but the latest changes close response stream too early. It is cause byusingin:using var internalResponse = await ExecuteRequestAsync(request, cancellationToken).ConfigureAwait(false);RestSharp/src/RestSharp/RestClient.Async.cs
Line 23 in 71c73f8
To Reproduce
Expected behavior
Be able to stream response to
API.Stack trace
Desktop (please complete the following information):
macOSNET 5110.2.0