Feature Request: leaveOpen in System.Net.Http.StreamContent


#1

Hi, there. firstly I hope I’ve got this post to the right place :slight_smile: I’ve looked for a right place on GitHub but failed.

Recently I’m using StreamContent with HttpClient to perform some file uploading operations. When I tried to implement the retry logic, I found out that

  • The passed-in HttpContent contained in HttpRequestMessage got disposed in HttpClient.SendAsync.
  • The underlying Stream in StreamContent got disposed in StreamContent.Dispose() invocation.
    This means that if I have passed in a Stream in StreamContent's ctor, the very Stream will be inevitably disposed after the first HttpClient.SendAsync invocation. This is not good, especially if the StreamContent-user is agnostic about how to reconstruct another brand-new Stream instance (but still can seek the position so the Stream will be at the same position as it is in the first call, as long as its CanSeek is true).

I ended up writing my own version of StreamContent that won’t dispose the underlying Stream when disposed. Still, I hope there will be some leaveOpen-like parameter in the constructor of StreamContent.


#2

The right place to post suggestions for new APIs is the corefx repo. Ideally, you should follow the API review process.


#3

Okay, thank you for pointing it out, svick. I must have been to the wrong repos…

And I’ve got a really, really, prompt response :joy:


.NET Foundation Website | Blog | Projects | Code of Conduct