Skip to content
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

FlurlResponse Get_Async methods don't accept CancellationToken #711

Open
develorem opened this issue Aug 9, 2022 · 4 comments
Open

FlurlResponse Get_Async methods don't accept CancellationToken #711

develorem opened this issue Aug 9, 2022 · 4 comments

Comments

@develorem
Copy link

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:

  • GetJsonAsync()
  • GetStreamAsync()

The underlying calls to HttpResponseMessage.Content.ReadAsStreamAsync() supports CancellationTokens, FlurlResponse should too

@develorem
Copy link
Author

@tmenier - Happy to implement this as it looks pretty straight forward? Just tell me which branch to start from.

@tmenier
Copy link
Owner

tmenier commented Sep 15, 2022

Yeah, this looks like an oversight. Pretty trivial enhancement, I'll get it out with the next 4.0 prerelease.

@tmenier tmenier added this to Backlog in Default Project via automation Sep 15, 2022
@tmenier tmenier moved this from Backlog to Planned in Default Project Sep 15, 2022
@tmenier
Copy link
Owner

tmenier commented Dec 20, 2022

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.

@tmenier tmenier moved this from Planned to Backlog in Default Project Dec 20, 2022
@cremor
Copy link

cremor commented May 3, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Default Project
  
Backlog
Development

No branches or pull requests

3 participants