You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow HttpCompletionOption to be specified when dispatching a request #123
HttpClient.Send accepts a HttpCompletionOption parameter that allows developers to stream a response rather than buffer it in memory. Buffering the response is perfectly fine for the majority of scenarios where the expected response is a reasonable size but streaming is a much better option when the response is large.
Currently, the FluentHttpClient does not allow developers to specify their desired completion option and by default Microsoft's HttpClient buffers all responses in memory. This means that we cannot enable the streaming of responses when we use FluentHttpClient.
Here's a sample scenario to illustrate when streaming would be desirable: let's say the developer issues a GET request to an API to download a file and let's say this file is quite large (I don't know exactly at what point a file become too large, but for the sake of this example let's say 100mb). With the current behavior, the entire content of the file will be buffered in memory and there's a real risk the developer will get a "Out of Memory" exception. If the developer intends to save the content of the file to disk, there really is no need to buffer the content in memory and streaming the content would be much better.
I propose the following changes:
Add a boolean property to the FluentClientOptions class to allow developers to indicate if they want responses to be streamed by default
Add a boolean property to the RequestOptions class to track whether the response to a particular request should be streamed or not
Add a boolean parameter to the WithOptions extension method which would make it easy for developers to turn on the streaming feature for a specific request
Modify the request dispatch logic to specify the appropriate completion option when invoking the HttpClient.Send method
Please note that my proposed changes 1, 2 and 3 would be consistent with how other options (i.e. IgnoreNullArguments and IgnoreHttpErrors) are currently handled by FluentHttpClient.
I will submit a PR with my proposed changes for review.
Thanks for merging my PR. Do you have an idea when you plan to release 4.4.0? No pressure, I'm just trying to figure out when I will be able to update my project which is waiting for this streaming feature.
Activity
Pathoschild commentedon May 12, 2024
Done in
developfor the upcoming FluentHttpClient 4.4.0. Thanks for the help!Jericho commentedon May 24, 2024
Thanks for merging my PR. Do you have an idea when you plan to release 4.4.0? No pressure, I'm just trying to figure out when I will be able to update my project which is waiting for this streaming feature.
Pathoschild commentedon May 24, 2024
I don't have a particular timeline, but I'll release the update today if you're waiting on the changes.
Pathoschild commentedon May 24, 2024
@Jericho FluentHttpClient 4.4.0 is now published!
Jericho commentedon May 24, 2024
Excellent. Thank you