Open develorem opened 2 years ago
@tmenier - Happy to implement this as it looks pretty straight forward? Just tell me which branch to start from.
Yeah, this looks like an oversight. Pretty trivial enhancement, I'll get it out with the next 4.0 prerelease.
Sorry for the long delay. It turns out this wasn't an oversight. Flurl relies on async methods off HttpContent
to implement these methods, and those didn't support CancellationTokens until .NET 5. Flurl still supports older platforms, making this tricky to implement without a bunch of compiler switches all over the place. Not impossible, but not trivial like I originally thought, so this won't make the cut for now.
You could use conditionally compiled extension methods to get CancellationToken support for this methods in older runtimes.
Examples: https://github.com/SimonCropp/Polyfill/blob/main/src/Polyfill/PolyfillExtensions_HttpClient.cs https://github.com/SimonCropp/Polyfill/blob/main/src/Polyfill/PolyfillExtensions_HttpContent.cs
edit: Ok, I just noticed that those HttpContent extension methods do not actually use the CancellationToken except for a check before requesting the content. So those are not really a good solution.
Please describe the feature/enhancement in as much detail as possible. CancellationToken is accepted on some async methods. While I haven't audited the code base, the class I care about currently is FlurlResponse and methods such as:
The underlying calls to HttpResponseMessage.Content.ReadAsStreamAsync() supports CancellationTokens, FlurlResponse should too