-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Http
Milestone
Description
Background and Motivation
We introduced HttpClient sync API in #34948. However, the access to response's HttpContent is still purely asynchronous (e.g. ReadAsStreamAsync). To fully support fully a synchronous flow we should also support synchronous read of HttpContent.
Proposed API
Following minimalist approach from #32125 we should add sychronous method to retrieve Stream from HttpContent.
namespace System.Net.Http
{
public abstract partial class HttpContent : System.IDisposable
{
// Existing methods:
protected virtual System.Threading.Tasks.Task<System.IO.Stream> CreateContentReadStreamAsync();
protected virtual System.Threading.Tasks.Task<System.IO.Stream> CreateContentReadStreamAsync(System.Threading.CancellationToken cancellationToken);
public System.Threading.Tasks.Task<System.IO.Stream> ReadAsStreamAsync();
public System.Threading.Tasks.Task<System.IO.Stream> ReadAsStreamAsync(System.Threading.CancellationToken cancellationToken);
// Proposed new methods, following the same implementation pattern as ReadAsStreamAsync and CreateContentReadStreamAsync
+ protected virtual System.IO.Stream CreateContentReadStream(System.Threading.CancellationToken cancellationToken = default);
+ public System.IO.Stream ReadAsStream();
+ public System.IO.Stream ReadAsStream(System.Threading.CancellationToken cancellationToken);
}
}Implementation Notes
All our own HttpContent implementations do have Stream readily available, see implementations of:
| internal virtual Stream? TryCreateContentReadStream() => null; |
Discussion Topics
CancellationTokensupport inReadAsStream(include or not)?- Include
CreateContentReadStreamboth overloads, one overload with default, or only one overload without default?
Prototype in #37494
cc: @dotnet/ncl @stephentoub
scalablecory
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Http