Skip to content

Add cancellation overloads on HttpClient and HttpContent #916

@baal2000

Description

@baal2000

It seems obvious that there is a lack of external cancellation support in a few HttpClient methods: GetByteArrayAsync, GetStreamAsync and maybe others. Any particular reason?

What is expected:

class HttpClient {
    public Task<byte[]> GetByteArrayAsync(string requestUri, CancellationToken token = default);
    public Task<byte[]> GetByteArrayAsync(Uri requestUri, CancellationToken token = default);

    public Task<byte[]> GetStreamAsync(string requestUri, CancellationToken token = default);
    public Task<byte[]> GetStreamAsync(Uri requestUri, CancellationToken token = default);

    public Task<byte[]> GetStringAsync(string requestUri, CancellationToken token = default);
    public Task<byte[]> GetStringAsync(Uri requestUri, CancellationToken token = default);
}
class HttpContent {
    public Task<byte[]> GetByteArrayAsync(CancellationToken token = default);
    public Task<byte[]> GetStreamAsync(CancellationToken token = default);
    public Task<byte[]> GetStringAsync(CancellationToken token = default);
}

I might be not alone here. If missed another case or the feature is in the pipeline already, then comment to the case and close as a duplicate.

Thanks.

P.S.
GetByteArrayAsync is another overload candidate mentioned by dotnet/corefx#32762.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions