Skip to content

More cancellation overloads for HttpContent #576

@MihaZupan

Description

@MihaZupan

Part of a series of issues adding cancellation support to HttpContent and HttpClient:
https://github.com/dotnet/corefx/issues/32615, https://github.com/dotnet/corefx/issues/9071

In order to implement HttpContent.ReadAsStreamAsync(CancellationToken) from dotnet/corefx#32615, an additional overload for CreateContentReadStreamAsync is needed (see comment).

The default implementation would drop the CancellationToken and call the existing overload. This is the behavior that was decided for SerializeToStreamAsync in dotnet/corefx#9071.


HttpContent also lacks support for canceling CopyToAsync.


Proposal:

partial class HttpContent
{
    // Existing
    protected virtual Task<Stream> CreateContentReadStreamAsync();
    // New
    protected virtual Task<Stream> CreateContentReadStreamAsync(CancellationToken cancellationToken);


    // Existing
    public Task CopyToAsync(Stream stream);
    public Task CopyToAsync(Stream stream, TransportContext context);
    internal Task CopyToAsync(Stream stream, TransportContext context, CancellationToken cancellationToken);

    // New
    public Task CopyToAsync(Stream stream, CancellationToken cancellationToken);
    // Change internal => public
    public Task CopyToAsync(Stream stream, TransportContext context, CancellationToken cancellationToken);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions