-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The response stream from AdvancedResponseWriter is disposed too early #2072
Comments
I think you are using the advanced response writer for the wrong purpose. It's meant to rewrite the response, and it should finish within the scope of one request, before the response is returned. The stream you get as an input should not be used outside of that closure. You might want to use |
My use case is to inspect the headers before executing the actual download. How would this be possible with DownloadStreamAsync? |
You can create a function based on public async Task<Stream?> DownloadStreamAsync(RestRequest request, CancellationToken cancellationToken = default) {
// Make sure we only read the headers so we can stream the content body efficiently
request.CompletionOption = HttpCompletionOption.ResponseHeadersRead;
var response = await ExecuteRequestAsync(request, cancellationToken).ConfigureAwait(false);
var exception = response.Exception ?? response.ResponseMessage?.MaybeException();
if (exception != null) {
return Options.ThrowOnAnyError ? throw exception : null;
}
if (response.ResponseMessage == null) return null;
return await response.ResponseMessage.ReadResponseStream(request.ResponseWriter, cancellationToken).ConfigureAwait(false);
} |
Ah sorry, You still can use /// <summary>
/// When supplied, the function will be called after the request is complete
/// </summary>
public Func<HttpResponseMessage, ValueTask>? OnAfterRequest { get; set; } |
My current thought is to change the interface signature and make Download work differently. Right now, it returns So, the idea is to make The first step there was to create a source generator to create instance of |
Continues in #2226 |
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 useRestSharp.RestClient.DownloadStreamAsync
), but the latest changes close response stream too early. It is cause byusing
in: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):
macOS
NET 5
110.2.0
The text was updated successfully, but these errors were encountered: